First things first: What is a code smell?

According to Martin Fowler

A code smell is a surface indication that usually corresponds to a deeper problem in the system.

So, code smells are signals that your code is not in very good shape, and should think about refactoring it.

Every software has some code smells. Some have low severity code smells, but some have very bad code smells. I was watching the Clean Code and in the video, no other than Uncle Bob (Robert C. Martin) explained what makes bad code smell so bad.

Because of the usefulness of that, I am bringing up the 4 main reasons mentioned in the video that makes a code smell bad.

Rigidity

Rigidity is the tendency of a system to resist change. A system is rigid when that system requires us to make many changes to many different places in order to fix a single bug or add a single new behavior. Such a system resists change, and so we say it is rigid.

A rigid system requires multiple changes, in multiple places just to make a simple change.

Fragility

A fragile system is a system that malfunctions in many unpredictable ways when a single simple change is made. We say that a system is fragile when the repair of a single bug or the addition of a single new feature causes a malfunction in one or many other parts of the system that have no connection with the part that was changed

I think this is the worst, as we are always afraid to make some changes as we do not know where it will break.

Inseparability

An inseparable system is a system in which those parts that might be profitably used in another system cannot be separated out from the first system. Indeed, we say that a system is inseparable when the various points of that system cannot be independent and be used in some other system.

Inseparable systems are unpredictable. You never know if you can reuse the components in the system, and so the changes cannot be reliably estimated.

Opacity

Opacity is the tendency of a system to be so ineptly structured that no amount of effort can be applied to divine the author’s original intent. We say that a system is opaque when reading the code tells us little or nothing about what the system does or the way it works.

Opaque code is hard to read, hard to understand, and hard to change.


One way to make a better code is to write a clean code.

Happy coding!


Photo by Juanjo Jaramillo