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

## Recommended Posts

Waaayoff    952
Incidentally, i really think this forum needs to support polls.

szecs    2990
Yes.

##### Share on other sites
SiCrane    11839
If you want to submit a poll idea you can. In any case, my capitalization conventions depend on what language I'm using. Ex: in C#, I use the .NET naming conventions which, for instance, specify names LikeThis for public functions, but in C++ I use names like_this for functions and variables.

##### Share on other sites
c_olin    197
No. In C++ I find the following convention the most readable with the least amount of conflicts.

Class names in upper CamelCase.
Variables/object instances in lower camelCase.
Namespaces in all lowercase.
Don't attach any warts to variable names (no mCamelCase or m_camelCase for members).

I find C#'s convention (upper CamelCase for methods/properties) to be more unreadable when it starts to get busy. It is nice that all C# libraries follow the same convention though.

I do wish C++ had a standard naming convention (or that the standard library used a more modern one).

##### Share on other sites
Waaayoff    952
Quote:
 Original post by SiCraneIf you want to submit a poll idea you can.

I didn't know that, thanks :)

##### Share on other sites
Andy474    694
in C#
namespace fooman{     class Foo     {           //Varaibles           private int iMyAge;           private string sMyName;     }}

for private variables I always put a 'wart' on the front, it means in larger classes I can find what I need on intellisense by simply knowing why type it is e.g.

I wanna find my age, and I know its going to be an int I just type 'i' and it shows me all the integers I have.

##### Share on other sites
Telastyn    3777
Quote:
 Original post by Andy474in C#*** Source Snippet Removed ***for private variables I always put a 'wart' on the front, it means in larger classes I can find what I need on intellisense by simply knowing why type it is e.g.

If your class is large enough that you can't keep track of the fields available, you're doing something wrong.

That said, I generally follow language standards like SiCrane. Though I will currently tend to fall back to C# standards in C++ and other languages if I'm working on throw away code.

##### Share on other sites
For me, it depends on what I am programming.

Variables

theObject for variables in Objective-C, Java, and C#
the_object for variables in C

Function Name

TheFunction for Objective-C, Java, and C#
the_function for C

I think most important is to avoid conflict with the language's keywords, while being consistent enough to read your own code.

I also like to write

while()
{

}

while () {

}

because I hate seeing ") {" for some unknown reason.

##### Share on other sites
DimitriA    100
lowercase

EG

string lowerCase() {}

I just feel more comfortable with it than LowerCase(), and I find I can type lowerCase faster than LowerCase.. :p

##### Share on other sites
PrestoChung    334
Edit: In C++

I do:

All variables have at least 1 underscore (sometimes trailing like_)

Local variables are lower_case, Class or Global or Namespace variables are Upper_Case

Classes are UpperCase with no underscores

Methods are also UpperCase with no underscores

##### Share on other sites
Quasimojo    279
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.

##### Share on other sites
Ron AF Greve    900
Yes.

##### Share on other sites
Fuji    205
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.

##### Share on other sites
I use a lot of different ways but at work they make me code like this. No "_" and it must start lowercase.

calculateMedian()
setHeight()

##### Share on other sites
JoeCooper    350
Quote:
 Original post by c_olinClass 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".

##### Share on other sites
CodeStorm    127
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_;

##### Share on other sites
JoeCooper    350
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.

##### Share on other sites
owl    376
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.

##### Share on other sites
CodeStorm    127
Quote:
 Original post by JoeCooperI 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!

##### Share on other sites
JoeCooper    350
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++.

##### Share on other sites
Aardvajk    13207
Can't break the habit of UpperCamelCase-ing everything (actually, that's not called camel case, is it?).

I even do:

for(int A=1;A<2;++A){ }

but then again I've never worked on code in a group. I guess you just go with the flow. At least I stopped doing TClassName (Borland Builder has a lot to answer for) after some time spent on these forums.

##### Share on other sites
pulpfist    528
Over the years of my C/C++/Java/C#/Perl/Python programming endeavours I realize that my coding style has been drawn towards the D style, something I find to be just fine as I am currently in the process of replacing C/C++ with D.
So, I guess my answer is No

##### Share on other sites
tufflax    504
In Lisps you can name them with almost whatever characters you want, so you can used names like "not=", "int->string", "the-last-element" and "+" (yes, "+" can be a variable name). I love Lisp...

##### Share on other sites
owl    376
Quote:
 Original post by tufflaxIn Lisps you can name them with almost whatever characters you want, so you can used names like "not=", "int->string", "the-last-element" and "+" (yes, "+" can be a variable name). I love Lisp...

Honestly, the only moment I'd name a variable "+" is after smokin crack.

That said, Lisps is for junkies.

EDIT: 2 minutes after posting this I forgot I've had posted it. That, for some, might mean that Lisps rules.

##### Share on other sites
NightCreature83    5006
lowerCamelCase for variables (members prefixed with m_ because _ on it's own looks silly and makes code unreadable) and functions
UpperCamelCase for Classes
UPPERCASE for macros
lowercase for namespaces

And no hungarian code, encode a type in a variable name is wrong the name itself should be sufficient enough to guess it's type.

When stuff gets confusing an what something is change your highlighting setup so it's clear what everything is in one glance. E.g. color functions differenct from classes and variables.