Re: commit: UT_String class


Subject: Re: commit: UT_String class
From: Mike Nordell (tamlin@algonet.se)
Date: Sun Feb 11 2001 - 07:57:30 CST


Aaron Lehmann wrote:
> I'm very scared of string classes. Take a
> look at the College Board's apstring class
> (http://users.harker.org/hs/EnderB/APCS/classes/apstring.{cpp,h}).

If that is the type of a string classes you're afraid of I think it's only
healthy. That class looks quite dangerous. Not to mention its implementation
is, how should I put this, written by someone not really that good at C++.

> In fact, they strongly discourage the use of ANY C-strings.

Most of the time this is good advise.

> What's wrong with apstring?

Does it matter. This is not the string class I committed.

> (it doesn't even use realloc() iirc for some reason).

Perhaps because memory is allocated by array 'new'?

> Now, this rant was about a different string class. But many of the
> points apply to string classes in general. Yours could cause a mess if
> some strings are C strings and others are UT_Strings.

May I suggest you provide an example, just one, where this could "cause a
mess".

> But I haven't even looked at your code yet.

Perhaps it would have been better if you did this first, then you would
possibly be in a position to pass some informed judgement.

> My plea is:
>
> * Only use UT_String where it makes sense (i.e. something that's
> resized a lot for a good reason).

Well _of course_! Developers make judgement calls all the time. But I'd
change your "i.e." to "e.g.". This string class would be very useful in
places where we currently have char arrays of 'n' chars, but most of the
time only use 'n/8' -- 'n/2' of that space.

It is however *not* a general char[] replacement string class supporting
formatting this, streaming that and archiving. It's a very minimal class to
take care of only a handful of cases.

> In general, strings are low-level data structures that can be
> implemented well as NULL-terminated arrays,

Yes? And? If it's implemented it using a zero-terminated string, it's of no
ones concern. That's an implementation detail. The user user of it would
only use its interface.

> and I am very cautious
> about abstracting something as simple as this.

You actually believe string handling is easy?
You promote wasting memory by using char arrays that aren't even half full
most of the time? You think it's fun taking care of memory management
yourself? Fine, don't use it.

/Mike



This archive was generated by hypermail 2b25 : Sun Feb 11 2001 - 07:57:45 CST