Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kordova

[java] Your Variable Naming Conventions

This topic is 6065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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. =-

Share this post


Link to post
Share on other sites
Sun doesn''t always use their own standard in their examples :D

______________________________
catch (SpellingException e) {}

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I like to prefix my names with scope and type:

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

global SomeClass gclsClassInstanceName;

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!