4 ms·
I'm not so up on Java, could someone explain why they chose "->" for lambdas instead of the "=>" that C# and ES6 use, as those languages seem to me like they wo
by grokys 11y ago
I'm not so up on Java, could someone explain why they chose "->" for lambdas instead of the "=>" that C# and ES6 use, as those languages seem to me like they would be the first place to look for inspiration.
- LoneWolf 11y agoWhile I don't know the reason i like it because for me is easier to type -> than => (portuguese keyboard, TBH dont know the difference from english)
- Glide 11y agoThe - and = are right next to each other on an English keyboard.
- WaxProlix 11y agoAFAIK that's actually non-standard. Haskell and (more importantly, maybe) C++11 use the single-line arrow (->), as do Erlang and various ML dialects (interestingly, F# uses the single-line notation, too, while C# does not). Probably other languages as well.
- kodablah 11y agoIn addition to the other answers, I bet it's easier for a CFG to parse knowing that "->" can't also be "negate and greater than" (since negation is only a prefix op) whereas "=>" can easily be a fat arrow or greater-than-or-equal.
- serge2k 11y agoWhy would that be any harder? The tokens are different.
- kodablah 11y agoTrue, Java does not support => as an alternative for >= so the ambiguity does not exist. It was just a guess, but since it was probably not right, I decided to dig. This mail post[1] explains that the extra equals sign becomes a bit annoying w/ other equal signs in the same expression. 1 - http://mail.openjdk.java.net/pipermail/lambda-dev/2011-September/004021.html http://mail.openjdk.java.net/pipermail/lambda-dev/2011-Septe...
- bigtunacan 11y agoI have no idea why Java chose that, but thought it worth mentioning "->" has been in use for Ruby longer than the alternative .NET and ES6 syntax.
- tajen 11y agoI'm not an expert. C++ uses -> for pointer dereference, e.g. o->p refers to the property "p" of object "o". I would assume C# inherits from C++ and had to define another operator. Java probably followed Scala's notation, which is probably derived from mathematics where ↦ is an application (a function) and ⇒ is a simple logical implication.
- incepted 11y agoActually Scala uses =>, so Java went the opposite way. Kotlin also uses ->. Doesn't matter much in the long run, you'll get used to whichever your language favors after just a few days or writing code in it.