Java Lambdas Finalised!

It’s not like C# invented them either. Even LINQ came from HaskellDB and extended comprehensions, and list comprehensions themselves are a Prolog thing that found their way into Erlang. Like Picasso said, “great artists steal”.

Finding out that lambdas aren’t sugar for inner classes makes me wonder whether we’ll have to wait for libraries to bless us with lambda-fied versions of their cumbersome API (e.g. Collections) or whether there’ll be some sort of implicit conversion on top of it. Implicits from Scala, now there’d be a radical feature that will assuredly Never Make It In to regular java…

The pushback for basic features like anonymous functions was bad enough. I suspect anything truly original in Java will be met with pitchforks and torches.

C# is a bad clone of Java with some other features and I still find lambdas not very interesting and less natural.

I think the problem most of us find with Lambdas is that Java is a pretty low-level language when all’s said and done and this is a very high-level feature being bolted on to it. It obscures a lot of low-level wizardy under the scenes which makes it look like “magic” and many of us feel uncomfortable with stuff like that. But like garbage collection and JIT compilation it’s magic we’ll probably grow used to … with time. It’s just that this is an addition to something which already takes quite some explanation and mastery - Java, the core language - and every new bit added on just makes the whole darned thing harder to learn and master.

Cas :slight_smile:

I agree with you but my problem is both the syntax and the fact I was already happy with inner classes.

They do seem to do something a bit beyond inner classes which I can vaguely understand, especially as it seems to have needed a couple of new bytecodes to achieve it.

Cas :slight_smile:

I agree with you but my problem is both the syntax and the fact I was already happy with inner classes.
[/quote]
Inner classes are ugly and produces to much boilerplate code. I cant wait for lambdas. It will be the best thing that happened to java since the enhanced for loop.

WHAT? Then what is the point? Just syntactic sugar for anonymous classes?

Lame. If they want to do it then do it right.

Closure and lambda being synonyms is a natural way of thinking, since in Lisp, where this all originates from, lambdas close the lexical environment. Lambdas without closing it it is kind of lazy actually, because it doesn’t really offer anything new to the developer. It doesn’t enable him to do anything he didn’t already do.

+1

I don’t care much one way or the other about the closures proposal. If it’s in the language, I’ll use it (like generics) but I wasn’t hanging out for them (and I do know how lambda functions work from LISP, Javascript, Haskell etc). It’s just a flavour issue, not the second coming as some language bigots would argue.

@longino:
So if it does not add anything … why is it being added? Just so Java can be ‘cool’?

I sometimes wonder if people really want to program any more. Just following the next hype that brings nothing to the table except saving people from using the language as it was intended and/or some typing.

If I want to use features from a different language, why don’t I just use that language?

It is a matter of taste. Some people find them ugly, some other people like me find them easier to understand than these lambdas.

Yes, it’s just syntax sugar, but here’s a dirty little secret: all programming languages are just syntax sugar for turing machines (ala brainf*ck) or SKI combinators (unlambda).

Syntax does in fact matter. A lot.

While I agree with the general gist of your comment, as I’ve already quoted above, Oracle are claiming these aren’t just syntax sugar for inner classes - they’re implemented differently under the hood, and in a way that may allow improved performance over inner classes in the future.

When you compile java code with anonymous classes you get a seperate *$#.class file for each class which has always been a pet peeve for me. Hoping that these lambda things don’t do that same :slight_smile:

Last week I kinda agreed with that. Today, I kinda don’t.

It’s actually not that magical. It’s a concept borrowed from functional programming. Now, the interesting part is that if you write it in such a way, it’s clear (for the machine) that the order doesn’t matter, because there isn’t some kind of state. You only care for the result at the very end.

This allows the machine to do things in parallel. Intel’s River Trail (some parallel processing extension for JavaScript) demonstrated that this is indeed a pretty interesting approach and it can indeed work pretty damn well.

So yea, it actually is kinda interesting, because it can improve performance without the usual pitfalls associated with multi threaded programming. (Interestingly, SQL is kinda similar. The driver can re-arrange your statements and do some things in parallel if it looks like a good idea.)

Well, at least that’s the theory as far as I can tell.

My next CPU will probably have 8 cores. Without shortcuts like this, most programs won’t be able to do anything useful with those beefy resources. Would be a shame, really.

KEEP CHINA BRITISH! Err…wait!

I was reading some stuff about this the other day.

Putting some things together -

http://www.theregister.co.uk/2011/09/17/intel_parallel_javascript/ - this article, particularly the penultimate paragraph, together with this thread on Aparapi - http://www.java-gaming.org/index.php/topic,24778.0.html and the Aparapi FAQ item on lambdas - all starts to look kinda interesting for the future! :slight_smile:

Really? So all programming languages are the same to you?

Technologies are as good as they are useful. If they aren’t introducing anything new then in the end nothing has changed.

Syntax is just a tiny fraction of what matters in a programming language. The concepts behind it are the “meat” of it, that which will make people want to use it because it enables them to accomplish something they previously couldn’t.

You’re missing the point. All useful programming languages are the “same” in the sense that they are Turing complete (which if memory serves only requires 5 operations). The syntax of various languages, in effect, only create lots of different specialize versions of these operations. BUT sytnax (and paradigim) matter…a ton.

Syntax is everything to a programmer.

Cas :slight_smile:

I think you are the one who doesn’t get it.

Different programming languages are conceptually different in the sense that they employ complete different approaches to solving the same problem.

It means that using a different language requires you to think in a completely different way. It is not a simple one to one translation of the code.

An example of a worthy feature was LINQ in C#. LINQ is conceptually different than anything previously present in a mainstream language, and it really enables the developer to do things he couldn’t before. LINQ is more than syntactic sugar. It changes how you think about the software you are developing.