3 ms·
These constructs don't always make code any easier to understand / maintain. I have played a lot with NetBeans' feature that automatically translate loops with
by sacado2 11y ago
These constructs don't always make code any easier to understand / maintain. I have played a lot with NetBeans' feature that automatically translate loops with their "functional" equivalent. Sometimes the code was so clever I couldn't understand what was happening.
Sure, code is more compact, but compactness is not an end in itself.
- justinhj 11y agoCompactness is more of a side effect and can be a detrimental one. Personally I find that this kind of code is more declarative of intent than the more imperative for loop. By using particular functional tools for the job you're avoiding any possibility of a bug in your looping construct and making your purpose explicit. I also like how it removes boiler plate to handle different container types making it easier to switch to different ones.
- Glide 11y agoThis reminds me a lot of Resharper's refactoring common things to LINQ in Visual Studio. A lot of times I just ran it thinking "oh wow that's a neat way to do it" and then reverted it back because it wasn't a common idiom or it made it much harder to understand. The same thing is going to happen with Java 8 until the feature becomes less shiny.