Be a Programming Hero! Prevent Code Rot!

Those of us who are not programmers might not realize that code is not invincible against entropy. Code rot is the slow degradation in the performance of your computer software. Your code’s quality and responsiveness can deteriorate over time, here are two reasons why code rot can occur:

cider-apples-2908856_640.jpg
  1. Changed Environment: The code has been unused for a long period of time. For example, it can be some existing functionality that isn’t needed or requested anymore. Even though the code itself has not changed, the code has rotted because it no longer fits in its surrounding environment.
     

  2. Gradual Decay:  This code is actively used in the program, so it’s up to date with the environment. Instead this code rots by slowly getting worse in small details, an example would be by repeated changes or fixes to the code base.  Each individual degradation my not be detrimental but in aggregation they have a significant impact.  This type of code rot is in almost every code base to a varying degree.

Here are some key ways to help prevent against code rot:

Performing Unit Tests

This is considered the most effective way to prevent code rot. By performing both class and method level unit tests, you can make sure that your code remains fresh, stable and usable. If it isn’t, you’ve at least caught the problem early and before it compromised the whole system.

Positive results to all of your unit tests also provides visibility if you need to repair or restructure the code.  If some of your tests don’t pass after an adjustment, you’ll know exactly where the problem is.

Making it Less Complex

Another way to prevent code rot is to reduce the complexity of the code. By limiting the number of dependent code segments, you are less likely to encounter a failure if you make a change to one segment.   Reducing code dependency also makes it easier to perform the unit testing as there will be less branches to cover with your tests. Simplify your code as much as possible and avoid duplication.

Document it All

Another tried and true way of preventing code rot is to incorporate high documentation standards. Make sure there are guidelines and code standards in place for your team.  Be clear about the level of detail that is required for code comments. Ask yourself, if you and your team didn’t show up to work tomorrow, would another development team be able to open your application, read your code and comments and continue your work?  The more explicit the comments and code details, the more resources you have if a failure should arrive. Remember, it’s not about the quantity of detail, it’s more about the quality.