When most people think of the work The C2 Group creates, they envision beautiful designs and a well-planned user experience. I am inclined to agree our designers are top notch. I am constantly amazed at the work they produce, and I thoroughly enjoy implementing it. But the visuals created by our design team are not the only beautiful part of the final product. The developers at C2 work up a sweat make sure their code on the site is pleasing to work with and stays clean. In other words, the code doesn't smell.
A "code smell" is developer-speak for source code that works but is not living up to its full potential. A code smell will not prevent your web site from functioning, but it could hinder its performance, slow down development, or increase the cost of fixing bugs or failures. The code we write will not be smelly because we employ a few tricks of the trade to sniff out problem code.
In order to eliminate smelly code we strive to adhere to the "single responsibility principle". That is, every class should only do one thing. By doing this, we can quickly eliminate the two of the biggest offenders of code smell; long classes and sawtooth code.
- Long classes are code files that have grown too large. If we adhere to the single responsibility principle, classes should be small. Typically, a class that is large generally does more than one thing. By keeping our classes small it becomes increasingly difficult to introduce bugs when small sections of the application change.
- Sawtooth code is also known as complex conditionals. Code often needs to make decisions or loop over large datasets. However, when these conditionals become too complex it is a sign that we are trying to accomplish too much in a single conditional, thereby creating a bottleneck for the application. This can result in code that is close to impossible to fully test and is inherently risky to publish.
By eliminating code smells such as long classes and sawtooth code, we create code that is clean, easy to read, and easy to maintain. Code smell elimination is much of an art as the creation of the visual designs. There have been plenty of discussions around the office about how long is too long, what happens to classes that are unnecessarily short, and how complex is complex? These discussions are fun and a great way to spur conversations that lead to innovation and best practices. Sometimes it's hard work, but at the end of the day, we'd rather work up a sweat and get it right and create code without the nasty smell.
Scared you might have code smell on your hands? Contact the experts at The C2 Group for help!