Five reasons to spring clean your code

March in the UK is usually the time Spring arrives in the UK (although we seem to be back to blizzard conditions today!). A spring clean is a good tidy up to get rid of clutter, and it may well be a good time to consider it for your code for 5 reasons:-

1. Hindsight brings clarity. As a developer, you are often working with new technologies or releases. You do not always have the luxury of being an expert, having a clearly defined problem. It is only once you have implemented something that you can really see how well it works, and its performance/memory impact. The tests you wrote (you did, didn’t you) will check the result is correct while allowing you to tidy up the code.

2. Is it clear how your code works? Reading code makes you assess whether the code is clearly documented. If it is not clear how it works, it would be a really good idea to fix it now, before it really matters.

3. Stuff accumulates. As developers, we often build on top of what already exists. We leave things in rather than remove them which makes it harder to understand what the code actually does. A ruthless cull is a good idea on old code.

4. Things change. You need to scale up to handle much larger files or the customer has new requirements. New versions of Java also appear and you find that you can improve the code quality with new features (foreach loops for examples).

5. Test your tests. Before I tidy up any code I often deliberately break it (ie hard-code a variable to a magic number, swap a comparison, comment out code) and rerun my tests. If the tests do not pick this up, I know there is a blind spot in our tests. Once fixed, I can be confident that I can refactor the code safely.

We have been been working on a big spring clean as part of our big update to version 5 of our PDF library software (with some very cool new features I will be detailing in some future posts).

My preferred way to spring clean is to have a cycle of small change, test. If it passes, I commit to Version control and repeat. How do you like to ‘spring clean’ your code?

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Related Posts:

Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

2 thoughts on “Five reasons to spring clean your code

  1. Every reason is good to clean the code (including spring coming) but if it is not an everyday habit then it won’t work anyway. This is something that every dev should do on daily basis.

  2. I recently wrote an article with a similar spirit to this titled “Help Wanted: Developers Who Are Also Janitors” (http://www.coderslexicon.com/help-wanted-developers-who-are-also-janitors/) where I talk about the importance of going through code and cleaning it up as things get done. Your spin on it makes sense as well and I like the tip about the negative testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>