Code smell – finding something in the source code that might indicate a deeper problem – is one of the most common yet elusive challenges developers and IT organizations face. Why? Because there is no single solution for detection or elimination of code smells, and it can’t be done in batches.
Instead, code smells needs to be investigated on an individual basis — an inefficient undertaking in the eyes of developers. But when left unaddressed, code smells can easily develop into issues that degrade application performance, increase technical debt, and make it more difficult for IT teams to provide value over time.
In the sections that follow, we’ll dive deeper into the concept of "code smell" — what it is, what it looks like in practice, and how developers can proactively address it to reduce any negative impact.
Code smells are any indicator that there’s a bigger problem with your code. They arise from a number of causes, including developer ignorance (i.e., a new developer or a not very good one) , rushed coding (someone just trying to “get the job done”), or unclear standards (company didn't outline them for developers).
In any case, code smells are a sign that source code is messy or otherwise does not meet best practice standards in the developer world or at your organization.
Some of the most common types of code smells include:
It's the symptomatic nature of code smells that makes dealing with them complicated. They aren’t bugs or code errors — a specific issue with a clear fix. Code smells are a symptom that suggests low quality code. They can mean that there’s a larger problem, but sometimes they don’t. Coding is nuanced, and there are times when imperfect or “bad” code is necessary in a specific scenario.
For this reason, it can’t be assumed that a code smell is a sure sign of a problem — just that it’s a likely one. But for all that, they can't simply be ignored. Code smells have to be investigated and confirmed before they can be eliminated.
This, of course, doesn’t always (or even often) happen. There are plenty of scenarios where busy developers need to work at a rapid pace with little time to investigate code smells they encounter along the way.
When left untreated, however, code smell can eventually become code rot, where code degrades over time causing the initial problem to grow and grow. Code rot increases technical debt and inevitably impedes the development process, often slowing velocity or creating roadblocks to successful deployment of new updates.
CAST Software demonstrates how the accumulation of code smell and code rot increases technical debt and lowers business value.
Technical debt compounds as developers compensate for smelly code without actually doing anything to eliminate it. Code smell needs to be taken seriously and addressed continuously in order to keep applications optimized and basically healthy. Unfortunately, addressing it won’t happen so long as the job remains time consuming and undefined.
Developers need a streamlined, straightforward way to detect and eliminate code smell in real time — a way that doesn’t disrupt the work they’re doing.
Once a code smell is detected, there are a few different response options. First, it can be left alone with no action taken. This, as we know, puts organizations at risk for code rot and buildup of technical debt.
The next option is to investigate, rather than ignore, the smell and then to make a conscious decision not to deal with it. It may be, for example, that the code smell can’t be feasibly fixed. Of course, it could also be the case that it did not indicate a true problem.
The third option is refactoring — the primary way in which problematic code smell is eliminated.
Co-author of the book Refactoring for Software Design Smells, Dalhousie University assistant professor Tushar Sharma visualizes the three potential response options to code smell this way: no action, discard, or refactor.
The key is to build refactoring into the SDLC so that it happens regularly and never feels like an overwhelming, unexpected undertaking. Indeed, it should happen any time a new update or application feature is released.
When developers know that code smell elimination is a standard step in the process (i.e., they’re expected to do it and know when it’s supposed to happen), it becomes the norm rather than an ad-hoc task that always gets tossed to the side for later.
All this said, even regular manual refactoring can be a tedious and time consuming process. For this reason, the best way to continuously detect and eliminate code smells in real-time is with a software tool that can automate the process.
Tools dedicated specifically to code cleanup do this well. An even better approach is to pair such tools (or your manual code smell cleanup process) with a high-visibility value stream management platform that drives continuous improvement with a focus on delivering business value through IT.