Inefficient Name: Where The Streets Have No Name
The Goal: Reveal Intention
The ultimate goal of a symbol's name is to perfectly reveal the intention of the person who is using 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.
Weak Name | Strong Name | Explanation |
---|---|---|
squareRootOfSumOfDimensionalDifferences | distance | The 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. |
- 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?
Why are we doing this?
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |