Code Smell 197 – Gratuitous Context

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…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Maxi Contieri ⭐⭐⭐

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

  1. 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

More Info

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

This article is part of the CodeSmell Series.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Maxi Contieri ⭐⭐⭐


Print Share Comment Cite Upload Translate Updates
APA

Maxi Contieri ⭐⭐⭐ | Sciencx (2023-02-21T17:59:58+00:00) Code Smell 197 – Gratuitous Context. Retrieved from https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/

MLA
" » Code Smell 197 – Gratuitous Context." Maxi Contieri ⭐⭐⭐ | Sciencx - Tuesday February 21, 2023, https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/
HARVARD
Maxi Contieri ⭐⭐⭐ | Sciencx Tuesday February 21, 2023 » Code Smell 197 – Gratuitous Context., viewed ,<https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/>
VANCOUVER
Maxi Contieri ⭐⭐⭐ | Sciencx - » Code Smell 197 – Gratuitous Context. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/
CHICAGO
" » Code Smell 197 – Gratuitous Context." Maxi Contieri ⭐⭐⭐ | Sciencx - Accessed . https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/
IEEE
" » Code Smell 197 – Gratuitous Context." Maxi Contieri ⭐⭐⭐ | Sciencx [Online]. Available: https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/. [Accessed: ]
rf:citation
» Code Smell 197 – Gratuitous Context | Maxi Contieri ⭐⭐⭐ | Sciencx | https://www.scien.cx/2023/02/21/code-smell-197-gratuitous-context/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.