# Code Smell 176 - Changes in Essence

*Mutation is good. Things change*

> TL;DR: Don't change essential attributes or behavior

# Problems

- [Bijection](https://maximilianocontieri.com/the-one-and-only-software-design-principle) violation

- [Mutability](https://maximilianocontieri.com/the-evil-powers-of-mutants)

- [Ripple Effect](https://maximilianocontieri.com/code-smell-16-ripple-effect)

# Solutions

1. Protect essential attributes from change.

2. [Remove setters](https://maximilianocontieri.com/refactoring-001-remove-setters)

# Refactorings

%[https://maximilianocontieri.com/refactoring-001-remove-setters]

# Context

Heraclitus said:

> “No man ever steps in the same river twice. For it’s not the same river and he’s not the same man.”

The man stays the same in essence. But his body evolves.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/7c1ee7181f403225470c90c2f4668f99)
```javascript
const date = new Date();
date.setMonth(4);
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/c758d376a61469d8ce4266b6e9fbe115)
```javascript
const date = new Date("2022-03-25");
```

# Detection

[X] Manual

This is a semantic smell. We need to model which attributes/behaviors are [essential](https://maximilianocontieri.com/no-silver-bullet) and which are accidental.

# Tags

- [Mutability](https://maximilianocontieri.com/the-evil-powers-of-mutants) 

# Conclusion

We need to favor immutable objects.

Objects can mutate in [accidental](https://maximilianocontieri.com/no-silver-bullet) ways, not in essential ones.

# Relations

%[https://maximilianocontieri.com/code-smell-16-ripple-effect]

# More Info

%[https://maximilianocontieri.com/the-evil-powers-of-mutants]

# Disclaimer

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

# Credits

Photo by [Nick Fewings](https://unsplash.com/@jannerboy62) on [Unsplash](https://unsplash.com/s/photos/heart-arrow)    

* * *

> Changes in software design will eventually mean "one step forward, two steps back". It is inevitable.

_Salman Arshad_
 
%[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]
