Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


C++ coding standard


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 EvilNando   Members   -  Reputation: 92

Like
0Likes
Like

Posted 14 May 2011 - 10:30 AM

Please recommend me a C++ coding standard preferably one oriented to game making

thanks



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31769

Like
1Likes
Like

Posted 14 May 2011 - 10:35 AM

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

#3 jonathanjansson   Members   -  Reputation: 271

Like
0Likes
Like

Posted 14 May 2011 - 12:27 PM

I like to compare naming conventions so wrote a review of two good ones below... I only consider naming here, not any other conventions.

I have tried the naming conventions from C++ Coding Guidelines by David Abrahams and Nathan Myers (an old document which pretty much is the Boost naming conventions) and .NET Guidelines for Names.

Both conventions has chosen to name pretty much everything in the same way.

Boost

Boost names identifiers using lower_case_and_underscores except for template parameters which are PascalCase. I believe the reason is to follow the C++ Standard Library conventions but also because in C++ the distinction between different kinds of identifiers can be blurry. For example std::sort can take either a function or an object as the comparator or an enum value can be used as a result variable in template meta programming.

Following the Boost style makes the code blend in with the standard libararies and Boost very nicely but I found that i got a lot of name collisions between types and variables. One can argue that you should come up with better names such as "player* shooter" but sometimes it seems impossible so I ended up typing "player* plr" and stuff. In the long run it was too much so I started using Pascal_Case_With_Underscores for type names and this worked fine.

After a while I got tired of this style and somehow the code doesn't look very firendly so now I try the .NET naming conventions instead.

.NET

.NET uses PascalCase for all visible identifiers and I think the point is to get naming collisions so it is easier to write code that is compatible with case insensitive languages. The nice thing here is that it only applies to names that are in any way public (or protected). Function parameters are named with camelCase and it is common to use camelCase for local variables and private data members too. Private variables are often prefixed with _.

This gets rid of most of of the name collisions I had using the Boost style. When I do get a collision it is because a struct has a public member that is named the same as it's type but you just have to come up with better names in those cases. Instead you can name variables the same as functions such as "Player* nearestPlayer = NearestPlayer()" or "Vector length = Length(vector)".

So far I like the .NET conventions. I think that PascalCase and camelCase styles are more common.

Edit

I have found that name collisions with C++ standard naming conventions is not a big problem. To declare a member variable with the same name as a type you just need to repeat the namespace before the type and it will work. Local variables with the same name as a type works without any tricks most of the time. Even when a type name is hidden by a variable name operator:: can be used to access static members of a class without repeating the namespace.

#4 rip-off   Moderators   -  Reputation: 8667

Like
0Likes
Like

Posted 14 May 2011 - 12:37 PM

I'm not sure how a coding standard could be oriented towards game making. What do you think a coding standard is?

#5 EvilNando   Members   -  Reputation: 92

Like
-9Likes
Like

Posted 15 May 2011 - 10:44 AM

I'm not sure how a coding standard could be oriented towards game making. What do you think a coding standard is?



My last 2 jobs had coding standards adapted to their field of work I'm too lazy to give you any more explanations so use google

#6 GregMichael   Members   -  Reputation: 143

Like
0Likes
Like

Posted 15 May 2011 - 10:55 AM

" I'm too lazy to give you any more explanations"

So why should rip-off or anyone else try and help you ?

From my experience, different companies have different coding standards...there isn't one book or reference that will tell you which one to use...they will all be different.

Try Google.

#7 SimonForsman   Crossbones+   -  Reputation: 6288

Like
0Likes
Like

Posted 15 May 2011 - 12:16 PM

My last 2 jobs had coding standards adapted to their field of work I'm too lazy to give you any more explanations so use google


Wow, just ... wow.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#8 rip-off   Moderators   -  Reputation: 8667

Like
2Likes
Like

Posted 15 May 2011 - 12:23 PM

Ok, here is a sub-convention. It may be added to any other coding convention to make a "game oriented" convention:

Game Orientation

  • All types, functions and data should be in some way useful to the making of games. Types, functions or data that have no use in game making (direct or indirect) are discouraged.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS