# Code Smell 197 - Gratuitous Context

> TL;DR: Don't prefix or suffix your names with irrelevant information

# Problems

- Lack of Polymorphism

- Bad Naming

- [Bijection](https://maximilianocontieri.com/the-one-and-only-software-design-principle) 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

[Gist Url]: # (https://gist.github.com/mcsee/0e69debe5bcce802a00b09be29a1a668)
```rust
struct WEBBExoplanet {
    name: String,
    mass: f64, 
    radius: f64, 
    distance: f64, 
    orbital_period: f64, 
}

struct WEBBGalaxy {
    name: String,
    classification: String,
    distance: f64, 
    age: f64,
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/111aa1f4c0d67b3230f6166aadecd9d6)
```rust
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

%[https://maximilianocontieri.com/code-smell-141-iengine-avehicle-implcar]

%[https://maximilianocontieri.com/code-smell-130-addressimpl]

%[https://maximilianocontieri.com/code-smell-174-class-name-in-attributes]

# More Info

%[https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab]

# Disclaimer

Code Smells are my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Mitchell Griest](https://unsplash.com/es/@griestprojects) on [Unsplash](https://unsplash.com/photos/psDzkLlifxQ)
    
* * *

> The most dangerous kind of waste is the waste we do not recognize.

_Shigeo Shingo_
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
