Neal Gafter will save Java or break his keyboard trying
In his latest musings on closures for Java, Gafter presents a structure for loop abstraction, noting that “iterating through a map is currently an ugly exercise in boilerplate.”
So true. Many of Java’s ills stem from long-term complacency towards boilerplate coding. Failing to find ways to factor out common problems, programmers have resorted to extensive copying & pasting of code scraps. After ten thousand presses of CTRL+V, that scrap might be labeled a “best practice,” or even a “pattern.”
Remember when JDBC first came out and you had to nest try...catch
blocks inside a finally
block to even talk to Oracle? (Some poor souls are probably still doing that.) We’ve come a long way since then, eliminating the window dressing and sometimes even the window-lifting, but in other places we’ve hit a wall.
Iterating through a Map is one of those places. If you can’t see it, you’ve written too little Java—or too much.
Add a comment