3 ms·
With more of an FP background (erlang / haskell) I was a little confused regarding when you would need to inspect variables outside the lambda. Won't the extern
by phamilton 12y ago
With more of an FP background (erlang / haskell) I was a little confused regarding when you would need to inspect variables outside the lambda. Won't the external variables be the same as they were before you called forEach? Why do you want to check that each iteration?
Then I realized that mutating variables is fairly common in a loop in procedural programming and that if you were to translate that to a forEach it would be useful to see what was going on.
I think the introduction of FP concepts in Java 8 is going to be interesting when it is not accompanied by immutability and other foundations in the language (or at least idiomatic usage like in Scala). I can't tell if that will cripple them or make them more accessible.
- jeorgun 12y agoIt's not like Java's the first imperative language to include FP concepts. Whatever lessons it can teach us, we could probably learn them just as well from Ruby, Python, C++, Javasript, C#, and so forth.
- phamilton 12y agoTrue, but those languages have a strong set of idioms for coding. For example, even though Ruby supports mutable calls, they are generally the exception and denoted with a ! (eg map vs map!) Meanwhile, Python is idiomatically opposed to map (to the point of intentionally crippling lambdas) in favor of list comprehensions. My concern is whether Java8 will spark a strong change in idiomatic usage or if it will just be another incremental change to the current status quo.
- cynicalkane 12y agoHis complaint isn't about not seeing mutating values each iteration, but that he can't see them at all. It's very common to want to know what's in the surrounding code, especially in the giant, incompletely specified and documented lumps of software characteristic of Java.
- douche 12y agoMy guess would be that lambdas in Java will look pretty much like lambdas in C#. Something like LINQ in Java would be quite nice.