Album Cover

Code Smells Java

Close Preview
The ultimate goal of a symbol's name is to perfectly reveal the intention of the person who is using it.
Weak NameStrong NameExplanation
squareRootOfSumOfDimensionalDifferencesdistanceThe first name reveals how the variable was set, which just isn't the same as what we intended it to do.
setBit7OnRegister3()turnOnLoopbackMode()What a method actually does isn't the point either. We need to know why someone would do it.
In both of these cases, the clearly preferable name is the one that describes what the programmer was trying to do.
The best names come from asking a question.
  • If it's a method, why would someone call it?
  • If it's a variable, why would someone need a variable containing that thing?
  • If it's a class, why would someone want these particular fields and methods bundled together?
Good names answer the WHY question:
Why are we doing this?
| Tweet...
Page rating: | Rate this Page