In programming, we often make a lot of mistakes, some break the code, and some do not. The ones that do not tend to bring down the efficiency of our code and make it very difficult to work with. Some of these mistakes have to do with the way we write the code, and they tend to hint at a bigger problem in the code design. These mistakes are called design smells. I think Martin Fowler defines coding smells the best, he defines them as a “surface indication that usually corresponds to a deeper problem in the system.” Design smells come in all different ways, but they usually stem from developers not following best practices. The end result is that the code either becomes too bloated, too inefficient or breaks easily. Luckily, design smells are rather easy to spot once you know what they are. Some of the more common smells are:
Rigidity – Program breaks in many places when a single change is made to the code.
Immobility – The code contains parts that could be useful in other systems, but the effort and risk involved in separating those parts from the original system are too great.
Opacity – This smell occurs when the code is difficult to understand and follow.
Fragility – The code becomes pretty difficult to change. A simple change could cause a cascade of subsequent changes in dependent modules.
Viscosity – When making changes to the code, it is easy to do the wrong thing, but hard to do the right thing.
Needless complexity – There are elements in the code that are not useful. Having them in the code is simply not necessary and it makes the code more complex than it needs to be.
Needless repetitiveness – There are too many repeating elements in the code that could be removed by using abstracted or refactoring the program.
These are things that we do not want in the code. In fact, they are considered technical debt. Technical debt is a term that describes the effects of mistakes or bad practices in code. As we program, we are going to make mistakes, errors, and sometimes not follow best practices. These shortcomings are things that we will have to revisit later today and spend time, resources, and effort spent on trying to fix and modify the code to make it work better. In this sense, it is similar to normal debt. Once you know the smells, it’ll become a lot easier to find them in your code. If you do spot design smells, then it is best to try to remove and solve the underlying problem.
https://martinfowler.com/bliki/CodeSmell.html
https://martinfowler.com/bliki/TechnicalDebt.html
From the blog CS@Worcester – Fadi Akram by Fadi Akram and used with permission of the author. All other rights reserved by the author.