Poll: Do you capitalize the start of your variables/functions?

Started by
24 comments, last by Brain 13 years, 6 months ago
I use:

UpperCamelCase for classes, functions and namespaces
lowerCamelCase for variables

I began programming many years ago with early FoxPro and Visual Basic, and the hardest bad habit I've had to break was adding warts to oVariables. I still catch myself doing it sometimes.

I'd be interested to know why some use all lower case for namespaces.

Good thread.
Advertisement
Yes.
Ron AF Greve
For classes, I use upper camel-case. For variables, I use lower camel-case.

class MyClass
int myInt

This is from a Java/Groovy/JavaFx background, however.
C++: Where your friends have access to your private members
I use a lot of different ways but at work they make me code like this. No "_" and it must start lowercase.

calculateMedian()
setHeight()

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Quote:Original post by c_olin
Class names in upper CamelCase.
Variables/object instances in lower camelCase.
Methods/functions in load camelCase.
Namespaces in all lowercase.
Don't attach any warts to variable names (no mCamelCase or m_camelCase for members).


That's the one I follow; Java uses these same conventions in the standard library. (e.g. java.util.List myList);

PHP really bugs me because of how completely random the naming conventions are.

The Strings section has 'html_entity_decode', 'htmlspecialchars_decode', 'printf', 'strcspn' and 'bin2hex'; words are abbreviated, shortened to a letter and underscores sprinkled in completely at random.

For me, I have to constantly check the manual. Rarely more than three minutes goes by without having to look somethin up. Because if you know the function is "Trim Whitespace", it could be trmwhtspc, trimwhitespace, trim_whitespace, trimwhite_space or a pictogram of a duck drawing a line on a check so you can't write in extra zeros.

It's like they found a bunch of manuals for different languages and stitched them together like the Frankenstein monster. Maybe they'll throw in some arabic function names from Phoenix just for good measure.

And their term for a map? "Array".
Depends.

For simple non-constant structures and built in types, I don't capitalize at the start, but I do use 'camelCase' thereafter for names consisting of more than one word. I.e.:

int variable;
long anotherVariable;

For classes, interfaces and functions I capitalize at the start, again using 'camelCase' for compound words:

CClass Class;
IInterface * TheInterface;

For constant data and macros I capitalize everything, using underscores for compound words. I.e.:

const int CLOCK_FREQUENCY;

It's all down to personal style I guess... There are no wrong ways or right ways, but whatever you chose, be consistent.

Totally agree with a previous post however, code like this;

void FooFunction (int x, int y) {
...
}

does my head in for some reason!

I much prefer such code to be written thus:

void FooFunction
(
int x,
int y
)
{
...
}

More writing perhaps, but much better clarity when faced with functions that take in several arguments.

For special "reserved" names in my code, I use a trailing underscore "_" to lesson the chances of a casual name clash with the rest of my code, and of course, with other system specific names that are usually reserved using leading underscores or double underscores.

I.e.

int reserved_;
I always use a leading underscore if I'm trying to denote something like that, for a practical reason; some editors with code completion will be able to narrow down the list of variables much faster if you put the underscore first. Instantly cuts every non-underscore name from the list. You can better take advantage of such typing aides.
In non-MVS c++ I opted for going all lowercase. I separate words with _.

void my_function_is_pretty(int teh_parameter);

In Visual Studio (thanks to intellisense) has little impact beyond astetics.
[size="2"]I like the Walrus best.
Quote:Original post by JoeCooper
I always use a leading underscore if I'm trying to denote something like that, for a practical reason; some editors with code completion will be able to narrow down the list of variables much faster if you put the underscore first. Instantly cuts every non-underscore name from the list. You can better take advantage of such typing aides.


Yeah... I used to use leading triple underscores on reserved names in my code, to avoid confusion with system specific names that use single and double leading underscored names, but after some thought I came to the conclusion that even leading triple underscores "breaks the rules".

Trailing underscores, as far as I can tell, are perfectly legal and are not reserved by the system.

At the end of the day, making use of namespaces should all but eliminate problems associated with leading underscores, but I guess I just prefer to stay "within the rules" as much as I can and besides, if another coder looks at my code, they could potentially misinterpret my leading underscored names as system ones.

But hey, each to their own!
Ohh, I didn't even think about that one. I got the habit in Java when I had some intermediate variable for argument; there's no builtins or anything using underscores in that environment.

Your way makes sense, especially in C++.

This topic is closed to new replies.

Advertisement