Naming variables and classes

I have such a big problem naming my variables and classes that i spend more time thinking about how to name them then programming actual code or debugging it. This might sound really stupid but this bother me alot. Isnt there some standard way of naming them, Some set of rules that could apply to all variables and classes i will create in the future?

Especially a for loop like

std::string sName=i cant type qoutation marks on this stupid keyboard
for(int i=0;i<sName.length();i++);

this is pure horror for me wat would be a apropiate name for the integer i?

Last edited on
closed account (3hM2Nwbp)
It's a pity, but there's no standard naming convention, so there's a near absolute chance that every other piece of code that you pick up will be written in a different style. It can be a bit annoying at times, but that's the world we live in.

Selfishly, I propose this set of rules that reflect my own preferences:

1) Please don't use Hungarian notation.

Jokes aside, I hope that helps.

In response to your latest edit:

1
2
std::string name = "Bob";
for(int i = 0; i < name.length(); i++)


i seems to be a common identifier (possibly abbreviating "index"?) for looping.

The problem lies when you get a blob of code like this:

1
2
3
float a, b, e, g;
int x, z, t;
//code that uses them all follows 
Last edited on
I think the best thing to do is pick a convention you're happy with and stick with it. (As long as it's not Hungarian notation ;)
For example:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Naming
www2.research.att.com/~bs/JSF-AV-rules.pdf
bool bIsThreadSplitIntoTwoForSomeReason = true;

http://www.cplusplus.com/forum/beginner/50422/
I am sorry for the double post i think something wend wrong after trying to read the RFC about TCP it must have done something to my brain.

Why is hungarian notation not a smart thing to use?

I think this will stay an issue will slowly go away once i have more experiance.
Hungarian notation makes it harder to read names, and since we all have IDE's that tell us the type of something if we just hover the mouse over the name, it doesn't add any information. Also, it binds the type to the name, so if you'd change the type of a variable during refactoring you'd also have to change its name.
Topic archived. No new replies allowed.