Last Revision — April 19, 2022
1 Min Read
Use Standard Nomenclature Where Possible
Lexical Abusers
Names
Within a Class
- Inconsistent Style (family)
William C. Wake in book (2004): "Refactoring Workbook"
Human brains work in a pattern-like fashion. Starting from the first class, the concept of operation and use of each subsequent class should be generalized throughout the project, facilitating and iteratively accelerating the speed of understanding how the code works.
For this reason, once we know that one class uses the method, store()
, we should expect that another class for the very same mechanic also uses the store()
name for that, instead of add()
, put()
or place()
.
In a team project, members could have omitted checking the existing naming in other classes [1]. They could also intentionally choose different naming methods to distinguish classes according to the naming convention of functions.
Standardized communication through names is vital for mental shortcuts.
The developer expects a method inside a sibling class but can't find it and has to look up synonymous variations of the method he wants.
class Human:
def talk():
...
class Elf:
def chat():
...
class Character(ABC):
@abstractmethod
def talk():
""" Converse """
class Human(Character):
def talk():
...
class Elf(Character):
def talk():
...