Live data from Hacker News

Java 8 Lambdas

datumedge.blogspot.co.uk

11–20 of 144 posts

Re: Java 8 Lambdas

#11
post #4
post #2

Congratulations to the Java-programmers for getting a feature that virtually every other OOP language has had for about 10 years.

Care to elaborate? Ruby had them from day 1, PHP has only had them since 5.3, not sure what the deal is with python.

C++, too has fine support for functional programming(since C++11)

Re: Java 8 Lambdas

#12
post #2

Congratulations to the Java-programmers for getting a feature that virtually every other OOP language has had for about 10 years.

And? Everyone agrees it would have been nice to have this a long time ago. It's still nice to get these features added now rather than never.

Re: Java 8 Lambdas

#14
post #4

Earlier quoted context omitted.

Care to elaborate? Ruby had them from day 1, PHP has only had them since 5.3, not sure what the deal is with python.

C# has had them for a little while now.

C# has had a notion of delegates since day one, and anonymous methods (like delegate(string foo) { ... } ) for 7-ish years.

C# lambda expression syntax (the =>) are about 4 years old now.

Re: Java 8 Lambdas

#15

Finally... and they even infer the type! Positively surprised. I will stick to Scala, though.

They can't _really_ infer the type. You just have to have one less set of pizzas. It doesn't work like scala's type inference.

Re: Java 8 Lambdas

#16
post #9

'sorted()' doesn't really act like that, does it - taking in a comparator function? It's much better to have comparator functions for the most common types baked in, and use projection to select a list of fields to use to compare with. Comparator functions are very easy to get wrong. The example given here - ".sorted((a, b) -> a.getValue() - b.getValue())" - won't work properly when the calculation wraps around.

> It's much better to have comparator functions for the most common types baked in, and use projection to select a list of fields to use to compare with.

Except that requires a sorting key for the result. Trivial for dynamically typed languages, but how do you handle the type of that key in a statically typed language? Mandate that the key be a string? Build a limited set of overloads against a dedicated type? And even then, how do you specify the relative constraints of the different values within that key, especially within the limitations of java's type system?

> The example given here - ".sorted((a, b) -> a.getValue() - b.getValue())" - won't work properly when the calculation wraps around.

But that's less an issue of "comparator functions [being] very easy to get wrong" and more an issue of "integer is an asinine type to use as ordering result". Even more so in a statically typed language. Haskell uses a dedicated enumerated type[0] which does not have this issue.

[0] http://hackage.haskell.org/packages/archive/base/latest/doc/...

Re: Java 8 Lambdas

#17
post #7

I'm curious to see what the implications are for other JVM languages given the promise of more efficient byte code.

That is already released in JDK7: the invokedyanmic bytecode -- JRuby is probably on the forefront of taking advantage of it.

Re: Java 8 Lambdas

#18
post #10
post #4

Earlier quoted context omitted.

Care to elaborate? Ruby had them from day 1, PHP has only had them since 5.3, not sure what the deal is with python.

Python has lambdas and functions as first-order values since the beginning.

You can't have statements in pythons gimped versions of anon functions :/

Re: Java 8 Lambdas

#19
post #5

I don't know how I feel about interface defaults. Why is that more important than say declared properties or unsigned types?

They are hugely important for introducing new behavior on existing interfaces without breaking compability. They are at the core of what is going to allow you to use all the new functional-style collection methods on your old collections without changing your implementation code at all.

Declared properties and unsigned types are relatively small changes. BTW, in JDK8 they have provided limited support for unsigned types, just not at the language level:

https://blogs.oracle.com/darcy/entry/unsigned_api

Re: Java 8 Lambdas

#20

Finally... and they even infer the type! Positively surprised. I will stick to Scala, though.

They can't _really_ infer the type. You just have to have one less set of pizzas. It doesn't work like scala's type inference.

It really does infer the type of the lambda. See Part F of the specification:

http://download.oracle.com/otndocs/jcp/lambda-0_5_1-edr2-spe...

Post reply on HN