Best naming techniques/conventions to use?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

Best naming techniques/conventions to use?

Post by Bullet Pulse »

I was just wondering what the "best" naming conventions are for programming in general.
For example, some books say to prefix static data members with s_.
Image
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Best naming techniques/conventions to use?

Post by Live-Dimension »

There is no "best" one per-say. The "best" one is to choose one that is easy to read and follow, and that you stick to. There are more ways out there then what you could realise, so google is your best bet to find one you like.

Peronally I find what works best for me so far is that all data members are lower case, all functions and classes, etc are uppercase starting, as well as function arguments. If there's another word in said symbol, then I also capitalise the start. It's a fast, efficient way of doing things. It's worked well for me in the past with other languages and so far it seems to hold up well in c++ as well.
ie

Code: Select all

namespace Nothing {}
ClassFunction(type ArgumentOne);
classMember;

...
You can quite easily overdo it on the naming conventions, and slow down your flow. The time it takes to keep your chosen convention in check goes up conventionally with how complex it is. . I *hate* underscores for this very reason. Any good IDE will tell you what the value type is anyway (pointer, static, etc).

Atleast, that's my reasoning.

edit: 100th post w00t!
Image
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Re: Best naming techniques/conventions to use?

Post by X Abstract X »

It doesen't matter as long as you stick with it for the entire project. If you decide to work on team projects your going to have to learn to adapt to different conventions to keep things consistent between team members anyway. With that said, there's certain language dependent naming conventions that should probably be avoided to prevent conflict (an underscore followed by capital letter or double underscores used to prefix an identifier in C++).
nardi11011
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 9
Joined: Thu Jan 28, 2010 3:24 pm

Re: Best naming techniques/conventions to use?

Post by nardi11011 »

I like to name everything LikeThis except for local and private variables which I name likeThis.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Best naming techniques/conventions to use?

Post by dandymcgee »

nardi11011 wrote:I like to name everything LikeThis except for local and private variables which I name likeThis.
Same. With the exception of constants which are LIKETHIS.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Best naming techniques/conventions to use?

Post by Live-Dimension »

dandymcgee wrote:
nardi11011 wrote:I like to name everything LikeThis except for local and private variables which I name likeThis.
Same. With the exception of constants which are LIKETHIS.
If it's in c++, it's generally a BAD idea to do that, as then you risk conflicting with marco's/defines. Assuming all of them are uppercase :P.
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Best naming techniques/conventions to use?

Post by dandymcgee »

Live-Dimension wrote:
dandymcgee wrote:
nardi11011 wrote:I like to name everything LikeThis except for local and private variables which I name likeThis.
Same. With the exception of constants which are LIKETHIS.
If it's in c++, it's generally a BAD idea to do that, as then you risk conflicting with marco's/defines. Assuming all of them are uppercase :P.
I suppose it's a matter of remembering not to name your constant the same name as your macro lol.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Best naming techniques/conventions to use?

Post by MrDeathNote »

dandymcgee wrote:
nardi11011 wrote:I like to name everything LikeThis except for local and private variables which I name likeThis.
Same. With the exception of constants which are LIKETHIS.
Ditto
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Best naming techniques/conventions to use?

Post by Live-Dimension »

dandymcgee wrote:
Live-Dimension wrote:
dandymcgee wrote:
nardi11011 wrote:I like to name everything LikeThis except for local and private variables which I name likeThis.
Same. With the exception of constants which are LIKETHIS.
If it's in c++, it's generally a BAD idea to do that, as then you risk conflicting with marco's/defines. Assuming all of them are uppercase :P.
I suppose it's a matter of remembering not to name your constant the same name as your macro lol.
You should let the compiler deal with that, not try to "remember". You completely skip human memory error when you don't do this. plus, I may add some SDK later on and it may just have the exact same name for a definition, especially if its a C SDK and not C++.
Image
Post Reply