In class, we did some activities about design smells, their definition, and what they do. So I was interested and decided to dig deeper and learn more about different design smells. I was curious because as a computer science major, I think knowing about design smells is very important especially how to avoid them.
In computer programming, design smells, also known as “code smells” are structures in the design that indicate a violation of fundamental design principles and negatively impact the design’s quality. Code smells are not bugs or errors. Instead, these are absolute violations of the fundamentals of developing software that decrease the quality of code.
Code smells indicate a deeper problem, but as the name suggests, they are sniffable or quick to spot. The best smell is something easy to find but will lead to an interesting problem, like classes with data and no behavior. Code smells can be easily detected with the help of tools.
How to get rid of code smell?
Code smells can lead to a serious defect in a program, failure of the whole system, and many others.
Once all types of smells are known, the process of code review begins. Two or more developers may use the primary method, the ad-hoc code review process to try and identify such smells manually. Many smells are not possible to be found by manual reviewing and automated code review tools are used for identifying such bad smells.
Code smells knowing or unknowingly are introduced in the source code, and may also form if you are solving other smells. Developers discard most of the smells consciously because they seem to have a marginalized effect or are just too hard to explain.
When developers find smelly code, the next step they do is refactoring. Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the software yet improves its internal structure. It may be the single most important technical factor in achieving agility. The goal is to stay within reasonable operating limits with limited continual damage. By staying within these limits, you keep costs low, because costs relate nonlinearly to the amount of repair necessary. Refactoring is a process in which the code is divided into smaller sections according to the identified smells.
A decision is then made to either remove them or replace them with a better series of code that may increase code quality and enhance some nonfunctional quality simplicity, flexibility, understandability, performance. After refactoring, run tests to ensure things still work correctly. Sometimes this process has to be repeated until the smell is gone.
I chose this topic because, as a computer science major with a concentration in software development, knowing about code smells is very important. When writing codes, we are supposed to be aware of this, so when it happens we know what to do to get rid of them.
What is a Code Smell and How to Get Rid of It? – QATestLab
What are Code Smells? | How to detect and remove code smells? (codegrip.tech)
From the blog CS@Worcester – Software Intellect by rkitenge91 and used with permission of the author. All other rights reserved by the author.