Re: Coding Style
On Mar 30, 11:50 pm, Hal Vaughan <h...@halblog.com> wrote:
This is more a style question, so I know it's subjective (I
hope I don't start a religious war!), but I'm also interested
to know if there is a trend.
I've noticed that a lot of C++ code shuns lower case and
basically tries to keep variables and functions with as short
a name as possible (or at least one that's easy to type).
You mean shuns upper case, of course. This corresponds more or
less to the oldest traditions in C. (If you've ever listended
to the output of a source listing on a teletype, you know why
they wanted to keep the number of characters to a minimum:-).)
I've not seen it much in C++, except when interfacing with
older, C libraries. Even in C, today, the tendency is to use
more readable names---compare the names in the more recent parts
of Posix (e.g. pthread_mutex_lock) with those from the orginal
Unix (e.g. ioctl), for example.
Functions might be like this:
But I've also noticed some code that uses underscores between words:
And here's the part I'm curious about. It seems to me that
more recent code seems to have the Java influence and is a bit
more focused on readability,
It's not Java influenced, and it's not particularly recent.
There are a number of variations in the different conventions,
but one main division is how you separate words in a symbol:
with an underscore, or by starting each word within the symbol
with a capital letter. The difference in readability is minor
(and IMHO probably favors the underscore). The two traditions
seem to come from different sources: most of the CCITT
specifications used capital letters (the so-called CamelCase),
so companies involved in any way with telephone systems tended
to adopt that, going back to the mid 1980's, at least. There
might have been other sources as well, since I don't think Java
was connected with telephone systems at its beginnings, and it
got it from somewhere as well.
so it's more like this:
In modern C++, I'd expect to see getValue() and
loadConfiguration() (or get_value() and load_configuration()).
Use of arbitrary abbreviations more or less went out with the
teletype. Other than that, all of the conventions require macro
names to be all caps, with an underscore between words, and all
modern conventions forbid anything else from being all caps
(with the frequent exception of single letter type argument
names to templates).
Is it just me, or does it seem that more code is written like
If by lately, you means since around 1990, maybe.
I read somewhere that a function name can be 30 characters
long but only the 1st 8 characters had to be unique, but my
experience with gcc is that it does fine with the 1st 8 chars
being the same (just toyed with it).
C and C++ have always allowed unlimited length in symbol names.
Early C did limit how many characters were significant, however,
with 31 (I think) internally, but only the first six guaranteed
accross modules (and no guarantee of case significance either).
Implementations have always been allowed to support more (and
I've never seen a C implementation which didn't support at least
eight externally). The current C standard requires 63
significant characters internally, and 31 externally (with case
always significant). C++ makes no absolute limit, but
recommends at least 1024 both internally and externally.
Does that have any effect on shorter names or maybe people
using different styles for names?
James Kanze (GABI Software) email:email@example.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