Sunday, 26 June 2016

What are the common Naming rules ?


NAMING RULES

#1. Use Intention-Revealing Names
int d; // elapsed time in days
int elapsedTimeInDays;

#2. Avoid Disinformation
Use below name only if this variable is a List type
accountList

#3. Long names which can take long time to differentiate
XYZControllerForEfficientHandlingOfStrings
XYZControllerForEfficientStorageOfStrings

#4. Use searchable names
Karakter
7
DAYS_PER_WEEK
week



#5. Make Meaningful Distinction
public static void copyChars(char a1[], char a2[]) {
  for (int i = 0; i < a1.length; i++) {
     a2[i] = a1[i];
  }
}


public static void copyChars(char[] source, char[] destination) {
   for (int i = 0; i < source.length; i++) {
      destination[i] = source[i];
   }
}



#6. Use Pronounceable Names
genymdhms

#7. Avoid Encodings
Example : Prefixing member variable with 'm_'
m_countryCode

Example : Interfaces & Implementation
Interface IShapeFactory {...}
Class ShapeFactory implements IShapeFactory {...}


Interface ShapeFactory {...}
Class ShapeFactoryImpl implements ShapeFactory {...}



#8. Avoid Mental Mapping
String url;
instead of 
String r;

#9. Don’t Be Cute
DeleteItems()
instead of
HolyHandGrenade()

dispatchRequest()
instead of
edenyFelRequest()

* Names based on cultural base or sense of humor will only be remembered by people who know it


#10. Pick One Word per Concept
Example : using fetch(), retrieve(), and get() in the same layer
* Caller will be confused which method to call ?


#11. Don’t Add Extra-free Context
Example : Prefixing every class with MBS in a Mobile Banking System
class MBSCustomer
class MBSSimCard

No comments:

Post a Comment

Note: only a member of this blog may post a comment.