Meaningful Names

  • Use intention revealing names: the name of a variable, function or class should answer why it exists, what it does and how it is used.

Let’s avoid:

List<int> list1;
  • Make meaningful distinctions: if variable names are different then they must mean something different, and that difference has to be easily understood.

Let’s avoid:

char[] a1;
char[] a2;
  • Use pronounceable names: use common words for names, instead of gibberish.

Let’s avoid:

class DtaRcRd102 {
private Date genymdhms;
}
  • Use searchable names: if a variable is used on several places on your code it should be easy to seach, so avoid numbers and single letter variables.
  • Class names: should be nouns or noun-like words.
  • Method names: should have verb or verb phrases as names.
  • Pick one word per concept: avoid having different namings for something that is fundamentally the same. For example, avoid having fetch, retrieve and get as different method names that do the “same”.
  • Use solution domain names: use algorithm names, pattern names, math names and so forth.
  • Use problem domain names: if no solution domain name is suitable, go ahead and use the name from the problem domain.
  • Add meaninful context: few names are meaningul in and of themselves, so it is always helpful when they are declared under well named classes, methods, namespaces, etc.