Sign in to follow this  

Coding conventions

This topic is 4548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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)
CapitalizedFunctions
lowercaseVariables
relatedVariable_a
relatedVariable_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.

Share this post


Link to post
Share on other sites
"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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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! :)

Share this post


Link to post
Share on other sites

This topic is 4548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this