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?
Latest posts by Mark Stephens (see all)
- 3 Reasons to attend NetBeans Day in Athens (17-18 April 2015) - March 24, 2015
- NetBeans Day UK – Friday 29th May 2015 - March 23, 2015
- Why we are abandoning ImageIO and JAI for Image support in our commercial Java code - March 19, 2015
- First impressions of the new RaspberryPi for Raspbian, Riscos, Java and NetBeans - March 3, 2015
- Converting a Swing application into JavaFX – Listeners and fast scrolling - February 3, 2015