Clean and Smelly Code

I was prompted to read through two different articles about clean code and smelly code. While reading through both articles, I found that the distinction between clean code and smelly code to be interesting, it’s a lot of little things that pile up to make code smelly.

If there was one thing that I think would be the most important aspect of clean code, it would likely be the readability or “clearness” [1][3]. Often times, when reading through code we wrote a long time ago we tend to forget the context and reason we wrote the code the way we did, not just through a lack of comments but also through a lack of clarity in the code itself. For example, if we have a number 0.1, we might want to make it a constant variable with a descriptive name, just in case we need to change something months later, so that we can quickly understand why that “0.1” was used. It’s something I want to try and do more, since I’m guilty of just using constant numbers very casually. Also, making code more efficient means less code that needs to be read later.

In fact, speaking of efficient code, a code smell I often find in my programs is long methods [2][4]. I often have trouble breaking long methods into smaller methods simply because often times I simply forget about doing it. I don’t place much importance in keeping my methods short, which may eventually lead to problems in the future. It can lead to duplicated code and it’s often easier to fix issues with methods when they’re short and therefore better to troubleshoot. I think many can relate to realizing that the issue with a method is a single line of code, and making methods shorter can make it easier to determine the source of problems.

While these things usually don’t affect our assignment grades, they are still important to understand when making code in a professional setting.

[1] Novoseltseva, E. (2021, June 20). Clean code: explanation, benefits & books – Apiumhub. Apiumhub. https://apiumhub.com/tech-blog-barcelona/clean-code-explanation-benefits-books/
[2] Atwood, J. (2019, August 7). Code smells. Coding Horror. https://blog.codinghorror.com/code-smells/
[3] Martin, R. C. (2008). Clean code: A Handbook of Agile Software Craftsmanship. Pearson Education.
[4] Fowler, M. (2018). Refactoring: Improving the Design of Existing Code. Addison-Wesley Professional.

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *