SameNameDifferentMeaning

Last edit October 11, 2013
Sometimes in code we find that the same names are used multiple places to mean different things. This is a CodeSmell that easily leads to misinterpretation.

Some examples:

Overloaded Vocabulary
This is the fault of DeGeneralization. Curses! Curses = The aptly named cursor control library under Unix??
  • "Thread" as in ThreadMode vs. "Thread" as in multi-threading.
  • "Pointer"/"Reference" in the C/C++ sense vs. the English sense.
  • "Serialize," as in "converting an object and, recursively, the objects to which it refers, into a sequence of bytes for storage to disk," vs. "serialize," as in "causing to occur in some sequence as opposed to potentially simultaneously."
  • "Order" meaning a request or purchase (order me a box of pencils) vs. "Order" for sorting and sequence (put the pencils in order)
  • "Invoice" (Backup, Archive, and many other words) which can be both noun and verb. "I have to invoice before you can have your invoice."
  • "static" keyword has different uses in C++: static variable keep its value even after it goes out of scope..and also static member variables, and static member classes.
  • ...many others. (TODO)

Identical Identifiers
Reusing variables for different purposes is a sign that your function has probably run too long, or that the variable is in the wrong (too global) scope. [SplitTemporaryVariable -- page 128 of RefactoringImprovingTheDesignOfExistingCode book.]


CategoryNaming