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)
- NetCat for NetBeans IDE explained in less than 5 minutes - July 16, 2015
- New APIs to handle PDF files in JPedal 6 – Forms - June 23, 2015
- New APIs to handle PDF files in JPedal 6 – General Features - June 16, 2015
- 13 things you missed if you were not at NetBeans Day UK - May 30, 2015
- New APIs to handle PDF files in JPedal 6 – Text - May 29, 2015