Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
Making changes and fixes to other people's code is never fun. It is especially not fun when naming conventions and basic programming principles like using getter/setter methods are not used. It gets worse when part of a naming convention was used to specify variable scope only to have someone come along and change this variable's scope and not update its name to match the convention. Then there is the issue of unused variables. Unfortunately the former set of issues is a little harder to deal with, but unused variables can be removed at zero cost and so are a quick win in terms of cleaning up bad code. The trick is configuring your IDE to let you do this easily.

As I am currently engaged on the operations side of the project I'm working on, coding is but a fraction of the work I do. I don't write code for new functionality, I also don't get the time to refactor or improve existing code, I can only change code when we find an actual bug that affects operations of the live system. This really limits what you can do to fix bad code and to make it more maintainable. So this had me thinking, maybe there is something that can be done during those times that I actually have to update some code that will improve the overall quality, and turns out there is.

Unused variables are a pain and can be seriously misleading when trying to comprehend a piece of code. All reasonable IDEs can also tell you when a variable is not used. The trick is to make your IDE really YELL THIS FACT OUT TO YOU.

I use JDeveloper mostly, in its syntax highlighting options you can configure what an unused variable would appear as. I've decided to set the appearance to look like a big warning sign, bold red text on a yellow background. You just cannot miss it.

Something like this:
codewarning.png


Every time I see one of those, it's a big warning sign to me, but also a big green light in terms of cleaning up the code.

I started to suggest that other people on the project do the same as well, in fact this should be standard for all IDEs, in my opinion.



-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...