Skip to content

Latest commit

 

History

History
98 lines (52 loc) · 3.4 KB

File metadata and controls

98 lines (52 loc) · 3.4 KB

Code Smell 176 - Changes in Essence

Code Smell 176 - Changes in Essence

Mutation is good. Things change

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

Problems

Solutions

  1. Protect essential attributes from change.

  2. Remove setters

Refactorings

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

const date = new Date();
date.setMonth(4);

Right

const date = new Date("2022-03-25");

Detection

[X] Manual

This is a semantic smell. We need to model which attributes/behaviors are essential and which are accidental.

Tags

Conclusion

We need to favor immutable objects.

Objects can mutate in accidental ways, not in essential ones.

Relations

Code Smell 16 - Ripple Effect

More Info

The Evil Power of Mutants

Disclaimer

Code Smells are just my opinion.

Credits

Photo by Nick Fewings on Unsplash


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

Salman Arshad

Software Engineering Great Quotes


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code