Coding conventions

Started by
5 comments, last by DigitalDelusion 18 years, 9 months ago
I'm sure this has been asked before but since the seach is buggered I thought I'll ask again. :D What is the recommended coding convention nowadays? Is Hungarian notation on its way out? I myself find it a bit of an eyesore but there is no denying it has some uses in that it spells out the nuances of the variable in one look. But with C# growing in popularity and better compilers I suppose there is a convergence towards a more standardised naming convention that is suitable for both C++ and C# coding techniques? Or maybe not, but I'd like to hear from you peeps here before starting up my new project with the necessary naming conventions in place.
"There is no dark side of the moon." - Pink Floyd
Advertisement
I despise Hungarian notation - it's extra stuff I have to type when I can just use the IDE features to see what type a variable is. The only time I use a prefix is on interfaces (IComparable, etc).

The only prefix I occasionally put on variables is the "m" or "m_" for member variables, and that's only if there's a remote possibility of using a similar variable name differently in function scope.

I use something pretty close to the coding convention that you see in most C# MSDN sample code:

CapitalizedClasses (no "C" on front)CapitalizedProperties (C# only, in C++ I use GetBlah, SetBlah or a reference return)CapitalizedFunctionslowercaseVariablesrelatedVariable_arelatedVariable_b

and the typical block layout with { and } on completely separate lines rather than putting the { on the same line as the compound-statement header.
"There are no Hungarian notation-using infidels in Baghdad. Never!"

"We are not afraid of the Hungarian notation. Allah has condemned it. It is stupid. It is stupid--and it is condemned."
--(the former) Iraqi Information Minister

In all seriousness, at work, we have no standard naming convention, just whatever we are used to. At most 2 people work on a particular program, and as long as the code is decently commented, we don't care the particulars of naming.

Of course for big projects, this would not be good, and all the programmers should follow some sort of common, logical convention. Just choose something that makes sense.
I think the most important aspect of using a naming convention is making sure it is used consistently by all coders. Whether or not your pointers are prefixed with a p or your classes with a C is of little consequence, and in the end comes down to personal taste. Just make sure your code is consistent.
Quote:Original post by RigidBody
I think the most important aspect of using a naming convention is making sure it is used consistently by all coders. Whether or not your pointers are prefixed with a p or your classes with a C is of little consequence, and in the end comes down to personal taste. Just make sure your code is consistent.



amen.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Right. Thanks for your inputs! I'll get cracking on setting up a coding convention for our project and with any luck it will be used consistently by the team of coders here. Or at least one can hope! :)
"There is no dark side of the moon." - Pink Floyd
For some inspiration have a look at the High Integrity C++ Coding Standard.

It doesn't directly deal with variable naming and low level stuff but gathers some really worthwhile advice on higher level constructs and conventions.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement