[java] Your Variable Naming Conventions

Started by
10 comments, last by kordova 22 years, 5 months ago
So, what does everyone here use typically for general variable naming? (This seems rather unimportant but I am interested to know whether people use the myVariableName or _myvariablename etc.) Thanks ahead of time for any responses.
Advertisement
Normally, I use the first one. All small letters, with capitals for the start of every word except the first.
int someReallyUsefulVariable = 5;


~~~~~~~~~~
"Usewhitespacetoenhancereadability" - Steve McConnell, Code Complete
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Why is the first letter not capitalised?

I usually just capitalise the first letter of every word in the variable name:

int SomeReallyUsefulVariable

When I make a class I prefix the class name with two letters describing what it is. For example, a Lightwave object:

class lwObject;


--------------------

Never eat anything bigger than your own head.
--------------------Never eat anything bigger than your own head.
Magmai''s convention is closest to mine: attempt to convey as much info as possible in the variable name about ownership, scope and type. I also employ the trailing underscore for parameters, but I haven''t used usffixes for units (nice idea, though!)


I wanna work for Microsoft!
The standards layed out by Sun are as follows.

variables always start with a lowercase letter and each word after that is capitalized to enhance readability.

classes always start with an uppercase letter.

in this way even if you dont use variable names that describe what they are.. ie firstNameStr ( with Str meaning String ) you will at least know that firstName is a variable and FirstName is a class.



-= programing is almost a performance art. We create the illusions on screen, knowing full well that in the background things may be very different. =-
-= programing is almost a performance art. We create the illusions on screen, knowing full well that in the background things may be very different. =-
Sun doesn''t always use their own standard in their examples :D

______________________________
catch (SpellingException e) {}
_______________________ http://mill.3dfxsweden.net
I use a slightly modified version of the Hungarian notation, i.e. classes begin with capital C, member variables begin with m_ etc. All names are in lowercase letters except the first in every word, e.g.:

class CMyClass
{
int m_nAnInteger;
};
/pitchblack
I use a mixture of casing and modified Hungarian notation to determine variable scope.

Prefix
I interface
C class
s_ static
m_ member variable
v_ volatile
g_ global
auto-local vars have no prefix

For functions, I use casing to differentiate function scope.
''Lower-Upper'' spelling (eg fooBar) for all static functions, protected members and ''Upper-Upper'' for all publically visible functions and public members.
I like to prefix my names with scope and type:

int mintSomeInt;
char *mastrSomeString;
int maintAFewInts[10];
long mlngSomeLongInt;

global SomeClass gclsClassInstanceName;
You people do realise that this is a Java forum and not a C/C++ one

- Kaijin

"If you find a job that you love you''ll never have to work again."

This topic is closed to new replies.

Advertisement