Re: Help with naming convention requested
On Jun 12, 5:06 pm, "Alf P. Steinbach" <al...@start.no> wrote:
* James Kanze:
I have a particular case where I'm having a problem deciding on
a good naming convention. Basically, I have several classes
which are split in two: there is a base class, which is a POD
(designed to support static initialization) and has only const
functions; and a derived class, which has the usual
constructors, and various non-const functions. A good example
of this is SetOfCharacter for UTF8: the base class has functions
template< typename ForwardIterator >
bool isSet( ForwardIterator begin,
ForwardIterator end ) const ;
(where the iterators designate a sequence of UTF-8 characters,
and the function returns true for the first character in the
sequence), and a function:
void dumpAsCpp( std::ostream& dest ) const ;
which outputs a declaration of the class with algomerate
initialization (with all of the necessary sub-tables in
anonymous namespace). The derived class has all of the
classical constructors, and the non-const operators, which build
and modify the data structure. The separation is essential
because it allows such objects to be statically initialized and
thus avoids order of initialization problems.
Consider using singletons, or completely rethinking that design.
How can singletons help, given that I have many, many instances
of the type?
Although that was in Java, I was once bitten by someone else's
decision to make static a lot of data and functionality that
was logically global single instance.
In this case, I'm not working in Java. I'm working in C++. In
the first version, I didn't use static data, and the program
took close to a half an hour to start. For a program that's
typically invoked just to process a few lines, that's simply not
(The program is a small processor, something like AWK, but a lot
simpler. The SetOfCharacter, and the related StateTable, are
used in regular expressions which are in turn used to tokenize.
The half an hour included parsing the regular expressions, etc.
And since the regular expressions are in fact constants---what
constitutes a token never changes---the obvious solution was to
make the entire parsed regular expression staticly initialized.)
I'd still like to bite that person back :-), but I don't
recall who it was.
It is also useful in a few cases for performance reasons:
one application uses several thousand such objects, and
dynamic construction can take a significant amount of time.
Several thousand function calls => microseconds => significant
It was more complicated than that, but the start up was on the
order of a half an hour. That is significant.
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.
Since you're aiming for POD'ness, how about including "POD" in
Because the POD'ness is a means to an end, and not a goal in
itself. And because it's the base class, and for most client
code, it's the class they should be using. In many ways, I
really think that SetOfCharacter should be the name of the base
class, with maybe MutableSetOfCharacter the derived class.
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=EF=BF=BDe objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=EF=BF=BDmard, 78210 St.-Cyr-l'=EF=BF=BDcole, France, +33 (0)1 30 2=
3 00 34