Re: generic programming: (in?)compatibility of CamelCase and
snake_case
On 22 mar, 21:55, Jeff Schwab <j...@schwabcenter.com> wrote:
Victor Bazarov wrote:
Jeff Schwab wrote:
Some people who clearly understand generic programming (probably a
good deal better than I do) seem to prefer CamelCase, even when
trying to interoperate with the C++ standard library. One striking
example is Andrei's book Modern C++ Design. What is the reason for
using CamelCase? Since static identifiers effectively define the
interface supported by each type, how is syntactic compatibility
maintained between CamelCase libraries and the snake_case STL?
What does a naming convention have to do with syntax? As long as
any identifier is valid and not a reserved one (which a convention
like CamelCase would ensure), what would be the objection to using
it?
Consider a naming convention that both method and type names
begin with capital letters. You define a container:
struct MyContainer {
//...
Iterator Begin();
Iterator End();
};
[Nothing to do with your question, but...]
More usual would be:
struct MyContainer
{
// ...
Iterator begin() ;
Iterator end() ;
} ;
One of the goals of a naming convention should be to distinguish
typenames from all other symbols.
If you have a generic function template designed to work with
standard containers,
If you have generic function templates designed to work with
containers, you haven't quite caught philosophy of the standard
library. Generic functions should be designed to work with
iterators. Where the names of the critical functions are *, ++
and ==; it's blatant abuse of operator overloading, but it does
avoid any argument about naming conventions.
it will expect the method names to be "begin" and "end", not
"Begin" and "End". To the extent that the actual and expected
names differ, the container and the function become
incompatible. The same holds for traits types, e.g. algorithm
implementations may need to know a container's value_type,
rather than its ValueType.
Certainly, when you want a name required by an external (to your
code) element, you conform to its requirements. The standard is
just one example; you don't call pthreadCreate, either.
I actually find this one (very small) advantage of camel case:
the reader knows immediately, from the way the name is formed,
whether the intent is to conform with some external convention
or not.
I'm not saying that any particular convention is superior to
any other, but that generic code is only as generic as the
naming conventions it expects. Expecting names to follow a
standardized convention is no different (AFAICS) from
expecting iterator types to support prefix increment and
dereference operations, or otherwise associating concepts with
syntax.
Exactly. The naming convention is part of the interface.
Without the interface requirements, you certainly wouldn't
overload ++ for an iterator, and without the interface
requirements, you might prefer the name ValueType, rather than
value_type.
--
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