This week I looked a little deeper into clean code and avoiding code smells. An article posted to medium.com details some good practices for keeping code clean. One thing from this article that I would like to start doing more often is YAGNI, or “You Ain’t Gonna Need It”. “Instead of trying to fulfill a necessity that isn’t present yet and creating a new feature or solution that doesn’t exist yet, keep your code DRY until you need to add more code for an actual problem or a new feature” (Soria). The article explains that DRY stands for “Don’t Repeat Yourself” and is another good practice to follow for writing clean code. I find myself running into this YAGNI problem more often than I would like. Rather than keeping my code simple and only writing what is needed now, I will think ahead and try to account for future problems before they arise and this can overcomplicate the code and make it harder to read.
Another article posted to techtarget.com discusses code smells, which it describes as code that is “inefficient, nonperformant, complex, and difficult to change and maintain” (Kanjilal). An example of a code smell that I hope to avoid in the future is dead code. An unintended side effect of my YAGNI habits is that it may lead to code that does nothing or code that has been commented out, either for future use or because it is no longer needed. Leaving this extra pointless code in the program makes it harder to follow and decreases the overall quality of the code and its cleanliness. I want my code to appear professional and clean so eliminating this dead code is absolutely necessary.
Citations
Kanjilal, Joydip. “Understanding Code Smells and How Refactoring Can Help: TechTarget.” Software Quality, TechTarget, 11 Mar. 2022, www.techtarget.com/searchsoftwarequality/tip/Understanding-code-smells-and-how-refactoring-can-help.
Soria, Agustin. “The Philosophy of Clean Code.” Medium, Medium, 11 Jan. 2024, medium.com/@soriaagustin8/the-philosophy-of-clean-code-b72791db82bf.
Leave a Reply