Names

Rules

  • Meaningful

  • Intentional - telling what it does

  • Readable, understandable

  • Self-explanatory

  • Not disinforming

  • Pronounceable

  • Consequent

  • Do not force 'mind-mapping'

Practice

  • Names just repeat the types - if types are correct and methods are small

  • The same object should have the same name when passed to other methods - not always but usually

  • Prefer positive conditional names - e.g. avoid !isNot()_

Some conventions

  • Class name: noun

  • Method name: verb

  • Avoid prefixes and technical terms (e.g. Abstract)

  • Name length corresponds scope length

  • Old Enterprise JavaBeans - EJB

  • Comply with: Java Code Conventions (Sun, 1997)

EJB - Enterprise JavaBeans

  • private Foo foo - foo is a 'property' name

  • public Foo getFoo() - the property name with a capital

  • public void setFoo(Foo foo)

  • public boolean isSomething() - also hasSomething()

Example: Bad: Names

Example: Good: Names

Example: Bad: Not informative names

Example: Good: Informative names

Example: Bad: Not informative name of input parameter

Example: Bad: Confusing characters (From the book)

Example: Good: Name lengths correspond to scope

Last updated

Was this helpful?