Static Imports are Evil
By Adrian Sutton
Michael Santos explores a few features of Java 1.5. As part of it he uses the new static import feature and asks what people think of it. I think it’s the most evil invention in coding I’ve seen since while (++i < 5) type statements. If you saw the line of code: long time = nanoTime();
where is the nanoTime() function? In 1.4 and below it is obviously in the current class – in 1.5 it could be anywhere and the only way to find out is to scroll all the way back up to the top of the file and read through every import statement. Then consider something like: err.println("Hello world.");
Where’s the print statement? Everyone knows about System.err.println so that must be it, unless err was a debug statement declared at the top of the file… Is it really that difficult to type System.nanoTime() instead of just nanoTime()? Programmers seriously need to learn some more discipline instead of always taking the easy way out and forgetting about the guy who has to read the code after them. In about 3 years time when I actually get to use Java 1.5’s features (backwards compatibility being as important as it is), the first thing that will be added to my coding guidelines will be no static imports – right next to no ++i or i++ embedded in other statements.