How to name variables and function properly

Hi guys. I have looked through others code. And i am seeing that people like to use _ when naming variables.

I wanted to ask, why are you doing this and are there any other rules i should know about.

Are there any typical rules when naming functions and classes?

Please tell me anything related also.

Thanks in advance!
There is a few rules on naming conventions, but specifically, a number can't be the first character of a variable/function name. That being said. I name all of my variables lowercase letter, and then each word, capitalize it. It's commonly known as camel case (numberOneVariableName). I do the same thing with functions and objects, but capitalize all of the first letters of each word (MyFunctionName). This helps me know what is what. I also use a Hungarian notation, but others have been pushing me away from it.
closed account (o3hC5Di1)
Hi there,

This is a highly individual choice - as you'll (normally) be the one that's looking at the code the most, it is important that you are comfortable with the style.
It is more important that whatever style you use, you use it consistently so that other programmers (and yourself) can always view your code in the same way.

Here are some wikipedia articles regarding the matter:

http://en.wikipedia.org/wiki/Programming_style
http://en.wikipedia.org/wiki/Naming_convention_%28programming%29

Hope that helps.

All the best,
NwN
@stoffe1100:
You should really pick a rule to follow or even make up your own
It is a great practice to keep yourself and your code consistent.
It brings readability and better maintainability

For my own preferences, I really hate this style :
1
2
3
//without the curly bracket
if (Test)
    DoStuff();


It just really pisses me off


Thanks for all good replies. Just the answers i was looking for :)
Last edited on
Topic archived. No new replies allowed.