Here are a couple links to read-up on:
- Functional vs "Java" Style
- Go Ahead: Next Generation Java Programming Style
- Next Generation Java is not very different from today's Java
Some interesting points all around, but I was very concerned with the condescending dismissal of using the final keyword, especially on local variables, making lame arguments about readability and clutter. If you want to talk about some actual clutter problems, start using more anonymous inner classes in functional style; now that is clutter.
Well, their (bloated) opinions (of themselves) are incorrect (after all this is a rant and My Opinion), because final is telling you important things about your code, namely that you believe in immutability, and don't just pay lip service to it. Just because Cedric
can't even remember last time I was bitten by a bug involving the reassignment of a variable to a different value within a code block.
doesn't mean Dick to us, but I'm sure it's good for his Ego! I guess we should all be so effin perfect as that, and final is the dirty little secret to take us there!
Thankfully, the comments sections bear this out, as I was delighted to see others extolling the virtues of final for the same reasons I endorse:
- Method parameters and previously-assigned local variables are not scratch-buffers to play reuse/optimization games with.
- Your code/dataflow are moving forward (literally down-the-page) and there's no need to look back and see if anything is getting re-used, or determining whether variables "magically" change meaning 10 lines into the method.
- The perceived noise claim is actually a Grail-shaped Beacon illuminating the locked-down nature of the data, which means visual scanning is rapid. If I see
finalI don't bother reading the rest of the line, because I know it's an immutable assignment guaranteed by the compiler. - The converse of this is that missing
finalis now a Bad Code Smell, and warrants closer examination.
The only part where it weighs down for me, is the conditional assignment initialization scenario, where you start down the jumping through hoops path to maintain finality:
final Blah theThing = big-fat-conditional ? value1 : value2; Depending on how hard you feel like working, and the complexity of the three terms, and any number of other (emotional) factors, you may punt on this scenario at some threshold; I've been there. Eventually the urge to rectify things takes over, typically after stopping at the code enough times triggered by the non-final "Smell".