What is Software Rot?

Decomposition is a natural function of all organic matter. This “rot” happens to plants and animals when exposed to microbial agents that cause decay, but it also happens in software when the system is exposed to completely different agents. Software rot, or software entropy, most commonly occurs over time as the code changes but the design doesn’t. These changes are referred to as “hacks,” and they are created by inexperienced developers but perhaps more commonly by rushed developers who must balance deadline urgencies with best practice. Frequently, under time constraints developers find it easier to add an IF statement or method overload to an existing design, creating a whole new code path in the system, instead of taking on the more complicated and time-consuming design change. Over time, as this process of code growth continues, the application becomes more difficult to understand and by extension to maintain.

Here are three common ways code rot can creep into a system over time:

  • follow Branching logic bolt-on:  A method may have been designed for only one code path. For instance, upon execution the method may have originally set a variable, performed a calculation with this variable, and returned the result. With code modifications over time, different code paths are added with If / else if statements. The method used to perform one type of calculation, but now, depending on inputs or class-scoped variables, the method can perform another totally different calculation. The more code paths there are through a class or a method, the greater the cyclometric complexity, which is way of measuring the decisional and conditional cases within source code.
  • orlistat 50mg Method overloading overload: when two or more methods are overloads of each other, the method name is the same, but the signature differs. In the next code block, the method CalculateNumber has four different implementations, when the class may have initially been designed for only one or two. After a while, as new developers join the team, discerning the reason for each version of CalculateNumber may become difficult. If a new developer doesn’t understand the reason for a method, this makes him or her more likely to create yet another overloaded method, hence accelerating the rot.
private int CalculateNumber()
{
    ...
}

private int CalculateNumber(int i)
{
    ...
}

private int CalculateNumber(int i, int i)
{
    ...
}

private int CalculateNumber(double y, double x)
{
    ...
}
  • http://heartsthatcare.net/ikWSQ/UgoTZ/ Object “T.M.I.”: “Too much information” about an object is exposed. this happens when a private variable or method is made public so that another object or component can access it. Perl programmers refer to this as “Object Orgy,” and when this happens the desired decoupling between this class and other classes and components is lost as methods and properties are exposed. Both method overloading overload and  cheap confidom object “T.M.I” are frequently found in classes that were designed to do one specific thing but underwent mangling to accomplish other tasks not originally intended.

Agile – both the solution and the cause

Sources abound stating that agile helps prevent software entropy (agile has also been touted to cure world hunger and baldness, but those findings have yet to be validated). Don Wells makes a good case here for Agile software development having the best weapons — such as refactoring, early delivery, unit testing – in the war against software rot. But like most things in software development and cat herding, it’s hard to find agreement. For example, Dylan Smith suspects agile is frequently the cause of software rot. The basis of his claim is that every sprint brings a new discovery which requires departure from design laid down in the previous sprint. Will the team be disciplined enough to pay that debt (and refactor the code) immediately upon discovery, or will debt payment be accumulated? On a similar note, in his presentation Practical Aspects of Software Life-Cycle: Decay, Ivory Towers, and other Topics, Reza B’Far writes, “It’s much like ‘let’s build a house… but we’ll just think about the first room, then once we’re done with that, we’ll think about the second room, etc.’ Sometimes it works out (if the house is small), but if you’re building a big house, good luck with that!”

How to prevent code rot

  • K.E.L – Keep exposure limited. When coding for a new feature or a maintenance task, developers should be suspicious of the urge to expose private properties or methods of an existing class (which leads to object “T.M.I.”). Just as with people, certain things about software objects are best kept private. This is a common way for rot to begin (not to mention the terrible embarrassment the system might feel after an indiscreet confession among mere acquaintances).
  • Simplicity – Every design will begin as the blueprint for the original intent of the system. But business changes and so do the needs of system users, and with these changes come challenges. Knowing when to modify an existing system versus replace it or compliment it with another new system should be part of the initial analysis.
  • The three-C’s – code reviews, code comments, and coaching. Code reviews and coaching are reinforced by good technical managers and architects. From that comes the developer’s compliance with code comment policy.