Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for member variables with initials

I was wondering how someone would name the member field that began with initials as opposed to words.

public class MyClass {

    // I know this is how it is for a member field with words.
    private String myString;

    // What about this String? It is representing the term "RV Scale" which is 
    // short for "Reclose Volts Scale."
    private String RVScale;

}

I know that I could just use private String recloseVoltsScale, but I'd rather keep it RVScale. If anyone knows if its supposed to be rVScale or RVScale or something else I'd appreciate the info.

EDIT :

Also, what about a member field like this...

private int RV;
like image 524
JuiCe Avatar asked Jul 30 '12 13:07

JuiCe


3 Answers

as per java naming convention member field should start with mixedcase so it should be rvScale and member field like RV should be like private int rv;

Using the right letter case is the key to following a naming convention:

Lowercase is where all the letters in a word are written without any capitalization (e.g., while, if, mypackage).

Uppercase is where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them (e.g., MAX_HOURS, FIRST_DAY_OF_WEEK).

CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter (e.g., CamelCase, CustomerAccount, PlayingCard).

Mixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase (e.g., hasChildren, customerFirstName, customerLastName).

like image 75
Harmeet Singh Avatar answered Oct 18 '22 04:10

Harmeet Singh


You should spell it out.

That being said, I would keep it rvScale.

Keep in mind that the only one that should NOT be used is rVScale since this can cause some confusion with introspection.

This case would generate getter and setter named getRVScale and setRVScale, but using bean introspection to find the property associated with these, would search for a property named RVScale, which doesn't exist. This is due to the fact that when searching for the corresponding property, the first letter after the get/set is lower cased, unless there are two adjacent letters in upper case (RV), in that case, the name is left as is, producing RVScale.

Like explained here:

Javabean convention - method naming for property gId

like image 28
pcalcao Avatar answered Oct 18 '22 02:10

pcalcao


Do not use shortcuts unless you need to. Even if they are private (or maybe because they are), name variables clear enough. If potential code reader does not understand rv as shortcut of something like Reclose Volts, do not use shortcut. If you need provide hint it is shortcut actually, you are hinting he should lookup it somewhere what does that mean. Where will he find it? If it is in comment, you have wrong name of member, as you have to explain what does the name mean. Unless you application is all about Reclose Volts. I suggest to follow java conventions as they did have reason to appear.

like image 32
Pihhan Avatar answered Oct 18 '22 04:10

Pihhan