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

| Views: 913
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

Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...