Page 1 of 1

Best naming techniques/conventions to use?

Posted: Wed Mar 10, 2010 8:19 pm
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_.

Re: Best naming techniques/conventions to use?

Posted: Wed Mar 10, 2010 9:30 pm
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!

Re: Best naming techniques/conventions to use?

Posted: Wed Mar 10, 2010 11:13 pm
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++).

Re: Best naming techniques/conventions to use?

Posted: Thu Mar 11, 2010 3:34 pm
by nardi11011
I like to name everything LikeThis except for local and private variables which I name likeThis.

Re: Best naming techniques/conventions to use?

Posted: Thu Mar 11, 2010 9:45 pm
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.

Re: Best naming techniques/conventions to use?

Posted: Fri Mar 12, 2010 5:13 pm
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.

Re: Best naming techniques/conventions to use?

Posted: Sat Mar 13, 2010 6:44 pm
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.

Re: Best naming techniques/conventions to use?

Posted: Sun Mar 14, 2010 2:34 pm
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

Re: Best naming techniques/conventions to use?

Posted: Sun Mar 14, 2010 4:57 pm
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++.