Re: Symbol Name Length (Was: STL Memory leak?)
On Apr 9, 1:14 pm, blargg....@gishpuppy.com (blargg) wrote:
Arne Mertz wrote:
[...]
Encoding the variable's type in the name often is no good
idea. First, you can see the types from the function's
parameter declaration. Second, in a more general case,
consider this:
std::list<std::string> optionList;
after some refactoring this is changed to
std::vector<std::string> optionList; //oops.
Encoding the type in the variable's name is duplication of
the type information (and therefore violates the DRY
principle), and it can (and eventually will) lead to
misinformation if the type changes as shown above.
Sometimes people object that changing the type SHOULD involve
revisiting all code that uses it, but in this case the
INTERFACE only changed slightly; most code using the list will
continue to work when using a vector, so this isn't
necessarily a change that requires revisiting everything.
Do you really think so? Presumably, if the author used
std::list, instead of the more usual std::vector, it could only
be because he needed some of the special characteristics of
list, e.g. the fact that insertion and deletion don't invalidate
iterators.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34