Re: C++ Programming Style
On Mar 30, 1:26 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
On Wed, 2011-03-30, peter koch wrote:
On 30 Mar., 09:50, "crea" <n...@invalid.com> wrote:
Is this a good c++ style
guidance:http://geosoft.no/development/cppstyle.html
I am trying to change my style to be constant.
It can not be recommended. A short glimpse reveals several errors -
the first one being, that constant identifiers should be all uppercase
(eg. int MONTHS_PR_YEAR = 12). This is plain wrong - did the author
come from Java?
I don't think you can call it "wrong". Their rationale is wrong, though:
"Common practice in the C++ development community."
Which makes me think that it's simply showing the age of the
guidelines. Until the late 1990's, and even later, it was the
usual practice.
Personally I do it that way too, but I'm aware that most people on
c.l.c++ don't (and you can end up in a flamewar by arguing for it.)
Two "arguments" are generally given against it:
-- You need something do distinguish macros (which don't obey
scope, and can modify syntax), preferrably something which
really stands out, and if you use all caps for constants,
it's no longer available for macros. People arguing this
point of view generally also point out that the tradition
comes from C---you don't find it in other languages---and in
C, such constants are macros, so it is justified.
-- "One man's constant is another man's variable":-). I
started arguing against all caps for constants when on
several occasions, the constants written in all caps ended
up being read from a configuration file.
The C++ community in general seems to have adopted the first
argument; there seems to be a large consensus about it. (I
think. To tell the truth, I've never verified.) The second
argument is, quite frankly, my own, and I've not been able to
convince many people about it, so it's not a concensus.
Anyway, the important concensus isn't the C++ community in
general, but the people actually working on the code. If most
of them do come from the Java world, or are old enough to have
experienced (and maybe liked) the earlier tradition, there's no
harm in adopting the convention of all caps, provided every one
is aware of the issues I mentioned, and provided you're aware
that the current overall consensus is different.
--
James Kanze