This is a nice way to mark 'your' classes and objects
TL;DR: Don prefix or suffix your names with irrelevant information
Problems
Lack of Polymorphism
Bad Naming
Bijection violation with names
Solutions
- Remove this context from your names
Context
In software development, gratuitous context refers to the unnecessary inclusion of additional information or data in code or user interfaces that do not contribute to the functionality or usability of the software.
It can make the software more difficult to use, understand and maintain.
It also increases the risk of errors or defects.
Sample Code
Wrong
struct WEBBExoplanet {
name: String,
mass: f64,
radius: f64,
distance: f64,
orbital_period: f64,
}
struct WEBBGalaxy {
name: String,
classification: String,
distance: f64,
age: f64,
}
Right
struct Exoplanet {
name: String,
mass: f64,
radius: f64,
distance: f64,
orbital_period: f64,
}
struct Galaxy {
name: String,
classification: String,
distance: f64,
age: f64,
}
Detection
[X] Semi-Automatic
We can find command patterns and rename all objects.
Tags
- Naming
Conclusion
Class Preffixing was a widespread practice decades ago to claim ownership.
Carefully consider the context and content of the software, and avoid including unnecessary or extraneous information wherever possible.
Now we know clean names are more important.
Relations
Code Smell 141 - IEngine , AVehicle, ImplCar
Maxi Contieri ・ Jun 18 '22
Code Smell 174 - Class Name in Attributes
Maxi Contieri ・ Oct 29 '22
More Info
What exactly is a name - Part II Rehab
Maxi Contieri ・ May 23 '21
Disclaimer
Code Smells are my opinion.
Credits
Photo by Mitchell Griest on Unsplash
The most dangerous kind of waste is the waste we do not recognize.
Shigeo Shingo
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.