On Jun 13, 2:27 am, Greg Herlihy <gre...@mac.comwrote:
On Jun 12, 7:36 am, James Kanze <james.ka...@gmail.comwrote:
For the moment, I've named the classes: BasicSetOfCharacter (POD
base class) and SetOfCharacter (derived class). I'm not
particularly happy with this, since it means that functions
taking a const reference really have to take a
BasicSetOfCharacter const&. Other alternatives I've considered
are ConstSetOfCharacter/SetOfCharacter and
SetOfCharacter/DynamicSetOfCharacter, but I'm open to other
suggestions as well.
I think that "CharacterSetBase" and "CharacterSet" (for the base and
derived classes respectively) would sound more natural and would
better convey the class' purpose. After all, a character set can be
any arbitrary collection of characters, it does not need to match any
of the "standard" character sets - although, of course, it might.
Exactly. I think you've understood what I'm working at. I
don't want to have to build up "[:alpha:]" at each execution; in
fact, practically, I can't, because I build it by reading and
parsing UnicodeData.txt. So it should be a statically
initialized constant. (In the actual application, a lot of
special sets can be as well, but [:alpha:] is a good example,
because it must be initialized externally.) On the other hand,
client code can (and in some cases does) create their own
SetOfCharacter, using the classical set operations.
I am currently using BasicSetOfCharacter and SetOfCharacter.
What I don't like about it is that most client code doesn't
modify its argument, and you want to be able to pass it things
like CharacterClass::alpha (the set for [:alpha:]). I'm thus
drawn to the idea that SetOfCharacter should be the non-mutable
base class, with something special to indicate mutability. On
the other hand...
With regards to CharacterSet vs. SetOfCharacter: the second
sounds more natural to me. Both Character and Set are nouns (in
this case, at least), and it seems more natural to join nouns
with a preposition than to just juxtapose them. But this could
just be me---it's been over 35 years since I last regularly
spoke English, and it's probable that I've lost a lot of my feel
for the language. (Now that you mention it, English is a
Germanic language, and in German, I'd definitely call it
Zeichenmenge, and not MengeVonZeichen.)
Moreover, you could also convey the const/non-const difference between
the classes with typedefs:
typedef CharacterSetBase * ConstCharacterSetRef;
typedef CharacterSet * CharacterSetRef; // or MutableCharacterSetRef
I would favor leaving out "dynamic" or "mutable" (since the absence of
"Const" should be enough). Note also that - although the two
CharacterSet typedefs are pointer types - the "Ref" in the typedef
name means that variables of this type are not expected to be null
(otherwise, I would use "Ptr" instead of "Ref").
I'm not sure about the typedef's, but I think you've raised a
significant point: in C++, mutability is implicit, and we mark
constness. If I base my naming on the language, the names
should be ConstSetOfCharacter and SetOfCharacter.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34