Thursday, December 4, 2014

Give me a proper name !!!

Hey White T-Shirt, Black Jeans on the street, listen to me.
If anyone calls you like this, how would you feel ????
Most probably, this is going to be your answer, 'Hey, stop insulting me you fool.'

Yeah, the same thing happens to variables too.

Now I suppose your name as human1, human2, human3 and so on...

Would you be happy with the name ???
Hey, I have a nice name (Angel or Prince can kill me if they get to me).

As, you are pretty sensitive about your name, please follow the same for your variables too.

There are some tips on it...

Java standards:

  • Variable names are case sensitive
  •  A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".
  • Subsequent characters may be letters, digits, dollar signs, or underscore characters.
  • Variable name must not be a Java keyword.
  • Name can not contain white spaces.
  • Digit at start is not allowed
 public class HibernateSpringTest {  
      public static void main(String args[]) {  
           int a;  
           int A;
           int $Abc;
           int _pci;
} }

Now, you can not understand why 'variables are used in this program. Java allows many names like human1, human2 etc. But can you understand who is human1 ?
No, not really Angel or Prince is quite good at it.

Please note that, as Java is case sensitive, 'a' and 'A' are different variables.

Standard conventions:
  • Don't use '$' or '_' as the first character of variable name. It is allowed but not suggested.
  • Please use proper variable names, which can suggest the way this variable is used.
  • If your variable name is span across more than one word, you can capitalize each first letter of each word.
  • While naming constants, use all capitals while separating each word by '_'

 public class HibernateSpringTest {  
      public static String EMPTY_STRING = "";  
      public static void main(String args[]) {  
           int counter;  
           int numOfNumbers;  

So, please be kind to your variables while writing your program. It will help to recognize why the variable is used for your team or other developers or may be yourself after 6 months you wrote the code.

Prev     Next
Palash Kanti Kundu

No comments:

Post a Comment