Recently I discovered the joy of "Save Actions" feature in Eclipse IDE. I can force it to reformat my code, insert missing
@Override annotations, and do some nifty stuff like remove unnecessary parenthesis in expressions or put
final keyword everywhere automatically every time I hit
ctrl + S. I activated some of those triggers and, boy, it helps a lot!
It turned out that many of those triggers act like a quick sanity check for my code.
- I intended to override a method but annotation didn't show up when I hit
ctrl + s? - perhaps I screwed up parameter types somewhere!
- Some parenthesis were removed from the code on save? - maybe that logic expression is way too difficult for a programmer to get around with quickly. Otherwise, why would I add those parenthesis in a first place?
- That parameter or local variable isn't
final. Does it have to change its value?
It turned out that the fewer variables change the less trouble I have at debug time. How many times you were following some variable's value only to find that it somehow changes from say 5 to 7? "How the hell it could be?!" you ask yourself and spend next couple of hours stepping in and out of countless methods to find out that you've made a mistake in your logic. And in order to fix it you have to add one more flag, a couple of conditions and carefully change some values here and there.
Oh, I hate debugging! Each time I run the debugger I feel like my time is running out and I desperately need that time to make at least some of my childhood dreams to become true! To hell with debugging!
finals mean no more mysterious value changes. More
finals => less flimsy parts in my code => less bugs => more time to do good stuff!
final classes and methods I don't really care. I love polymorphism. Polymorphism means reuse means less code means less bugs. JVM does a pretty good job with devirtualization and method inlining anyway so I don't see a value in killing possibilities for code reuse for unsound performance benefits.
Seeing all those
finals in the code is somewhat distracting at first and takes time to get used too. Some of my team mates still getting very surprised to see so many
final keywords. I wish there was a setting in the IDE for special syntax coloring for it. I would be happy to switch it to some shade of gray (like annotations) so they won't get too distracting when reading code. Eclipse currently has a separate color for
return and all other keywords but not for