Naming variables, functions...
Probably many of you use Hungarian notation for naming variables. But if you don't want to indicate what type of the variable it is, how do you name the variable?
Say, MyVariable, for example.
I noticed that many put the first word low case, and capitalize other words.
For example, myVariable.
Why is that? What is the most common way of naming variables and functions?
Re: Naming variables, functions...
Quote:
Originally posted by Ariod
I noticed that many put the first word low case, and capitalize other words.
For example, myVariable.
Why is that? What is the most common way of naming variables and functions? [/B]
When you write a variable, you want to have it describe what the variable is. for example, if you wanted a variable to hold the value of some widgets made in 1986, you might write:
numberofwidgetsmadein1986
Of course that is kind of hard to read, so you might write it with capital letters to begin each new word, like this:
numberOfWidgetsMadeIn1986
Now it is slightly easier to read. I did not capitalise the letter 'n' at the beginning of the variable, as I am lazy, and I don't like pushing shift more than I have to...actually I am lying, as you will see, I like doing more work than a lot of people when I name my variables... No sense in capitalising the first letter though, as its not needing any emphasis, as opposed to the words 'buried' within the variable, like 'widgets' and 'made.'
Another way to make your variable easier to read (and someone might scream when they see this..lol) is to use an underscore.
number_of_widgets_made_in_1986
This is my personal preference (even though it is slower to type with underscores) over against