Summary
In a recent blog post, Tim Bray warns of the dangers of making Java a vehicle for an increasingly complex set of programming language features.
Advertisement
As adding closures to the Java language is increasingly becoming a reality, many developers started to have second thoughts about extending Java with closures. The debate seems to center not around the specifics of any one closures syntax, but whether Java needs any language additions on the scale of closures at all.
In a recent blog post, On Closures, Tim Bray summarizes key arguments of this debate, and highlights why he thinks Java became so successful despite the language's shortcomings:
I started out nervous with the idea of adding closures to Java, and I think I’ve slid firmly into the “contra” camp. One reason is that it seems increasingly a bad idea to add anything to the Java language...
Java worked so well because it hit the 80/20 point; for my money one of the loudest, cleanest 80/20 technology victories ever. Subsequent attempts to fill in the 20% were, well, mostly harmless. Until generics, which are a disaster; they have made Java harder to learn and to understand, and you can’t avoid them...
So I’m really scared about trying to chip away any further at whatever’s left of the 20%. Also, I look at the motivating examples for closures and I think that the conventional alternatives aren’t that bad. Also, I look at the proposed code and I think that on balance it’ll make Java harder to read. Also, as Bharath points out, if you really need closures and and functional-programming goo and suchlike, there are at least two excellent Java-platform languages that have elegant, well-tested designs: Scala and JRuby.
Bray's point is that Java's open-sourcing has raised the bar for any new technology or proposal desiring to become a core part of the language:
Now that Java is Open-Source, anyone can go cook up whatever loony closure facility they want, and if it’s good enough, people will start using it whether the binary build has “Java” stamped on the outside or not, and then start shouting that it should be in the standard distro, and only then should the JCP consider going near this tar-pit.
Bray also points out that since the JVM is now open-source, making the VM more hospitable to languages that already have elegant closures facilities may be wiser approach than extending the Java language:
My favorite place to start improving Java wouldn’t be with the language at all, it’d be the Multi-Language VM project. The motivating use-cases for that aren’t theoretical in the slightest, they have names and addresses and are screaming for love.
To what extent do you think should Java incorporate new language features? Do you support adding closures to Java?
Tim seems to be working hard to kill Java as a language. Java needs to stay current or it will die. As a Java coder since 1996, a Ruby coding since 2004 and a Scala coder since 2006, I have come to hate writing Java code. One of the main problems with Java is the lack of closures/syntactically pleasing anonymous functions (read anonymous inner classes with a single method.)
I agree one hundred percent with Tim Bray! Stop adding "features" to java. It must be remembered that a program is written once but read many times (for maintenance or learning purpose) . The more features, the harder it is to understand.
Moreover, closures are just a disguised way to get rid of object orient programming and coming back to pointers!
Personnaly, I try to stay away from the new features as far as I can. Recently I had to port some software to a programmable modem, and I was happy I had not put generics everywhere in the code :-)
I agree stop loading java further to appease a minority. Java with generics has already become a tougher language to learn for the beginners. Java's beauty lay in simplicity. It was a beautiful manifest of 'Make things simple but not simpler'. Learning curve with Java was more associated with API and frameworks rather than the language (simple)features which made development so productive. Now adding the features not essentially needed is making it look a big-fat ugly troll. Going by the current trend developers will always be playing catch-up with java's new features and eventually they will stop gasping for breath and will hold onto another language. I'm a big lover of java and with all this shake-up even inertia of a lazy person like me is going to give in sooner or later.
I find it hard to take seriously anyone who calls generics a disaster. Generics have made Java code much easier to read. It is now for instance immediately clear what the type of objects in a collection is.
More language features do not (necessarily) make a program harder to understand. Compared to the amount of time I spend reading code, the time to learn a language feature is insignificant. So any feature that helps understanding code is a net win.
Also, while you would think that writing boilerplate code takes little time, I've read research showing that the time taken and the number of bugs created per line of code does not vary much over programming languages. So features allowing you to do more with less code can help productivity. (I have no problem coming up with unrealistic counter examples, this is not meant as an absolute statement.)
I'd suggest anyone who is against closures to do like David (see above) and do some serious programing in Scala, Haskell, or similar. You'd be amazed at the amount of unnecessary code you have to write in Java.
Maybe calling generics a disaster is exaggerating, but they are certainly broken. Had Sun the foresight to implement generics completely, it would have been a great addition to the language. Now though, it is a point of confusion for many. My understanding is that generics erasure will be eliminated in Java 7. That will help a lot.
I am a long-time Java programmer and I am very eager to get a good implementation of closures. Where I work, we run into so many situations where closures would make our solutions much cleaner and easier to maintain.
The fact is languages either evolve or die an early death. Java will be replaced by another, hopefully better, language. It's inevitable. We have invested in Java and would like to see it be viable for many more years.
I think there are many things that could be removed, but proper generics and closures are on the top of my 'must have' list.
It's too late for Java now. Java coders are used to 'for/while/do' loops, action listeners, etc. Closures will not be used except by the hardcore programmers.
> It's too late for Java now. Java coders are used to > 'for/while/do' loops, action listeners, etc. Closures will > not be used except by the hardcore programmers.
True for JavaEE programmers but there are many applications that are Java SE and it is very good for them. I think it is wrong to assume all Java development is Java EE, and it is wrong to assume all web development is Java EE.
> Maybe calling generics a disaster is exaggerating, but > they are certainly broken. Had Sun the foresight to > implement generics completely, it would have been a great > addition to the language.
Without erasure, generics would have almost certainly been rejected (and not just by Sun). The compatability hurdle is just too high to allow a completely satisfactory implementation of generics.
> Tim seems to be working hard to kill Java as a language. > Java needs to stay current or it will die. As a Java > a coder since 1996, a Ruby coding since 2004 and a Scala > coder since 2006, I have come to hate writing Java code. > One of the main problems with Java is the lack of > f closures/syntactically pleasing anonymous functions > (read anonymous inner classes with a single method.)
From what you just said, it seems that you agree with Tim that the Java VM should be a friendly environment for other languages as well. Note that Ruby and Scala are both running on the VM. What more do you want. You can use Ruby and Scala, and still use your existing Java stuff. If we ever get closures in Java (and I'm also in the 'no' camp now) it will not be anywhere close to closures in Scala or Ruby. I you are using Scala and Ruby now, I don't see why you would return to Java to get awkward closures.
"Without erasure, generics would have almost certainly been rejected (and not just by Sun)."
Maybe you are splitting hairs? Would it be better for me to say "support for reified generics?" This can be done with migration compatibility. I believe at least one proposal was suggested for generics but I am not sure.
What's the trouble with understanding generics? Doesn't *everyone* know you can't put a Car into a List and pull out a Chicken? If a programmer can grasp that much, then he'll understand how to use generic based containers in most cases. Otherwise, why *ever* let him *near* a non-generic List?
> What's the trouble with understanding generics? Doesn't > *everyone* know you can't put a Car into a List and pull > out a Chicken? If a programmer can grasp that much, then > he'll understand how to use generic based containers in > most cases. Otherwise, why *ever* let him *near* a > non-generic List?
It's not that. What's starts to create confusion is why a List<String> isn't a List<Object> leading to the discovery of the '? extends' and '? super' declarations and a good bit of confusion of when to use them.
Then, what exactly this means and why it doesn't compile cleanly:
class Foo<E extends Foo<E>> {
E getThis() {
returnthis;
}
}
Neils Bohr (IIRC) said that anyone who wasn't shocked by quantum theory hadn't really understood it. I kind of feel the same way about Java generics. If you don't think it's confusing, you haven't realizes how truly complex they are.
I don't believe this is true for all generic type systems. Java's is just particularly odious.
> Tim seems to be working hard to kill Java as a language. > Java needs to stay current or it will die. As a Java > a coder since 1996, a Ruby coding since 2004 and a Scala > coder since 2006, I have come to hate writing Java code. > One of the main problems with Java is the lack of > f closures/syntactically pleasing anonymous functions > (read anonymous inner classes with a single method.)
quite the contrary. It's the people who are stuffing everything and the kitchen sink into the language who are killing it (intentionally or otherwise).
Simplicity and a clean syntax is what makes Java a success, turning it into a mix of C++, Ruby, Python, and Visual Basic (which it exactly what's happening with all the nonsense being "proposed") destroys that.
We don't need function pointers (a.k.a. "closures" to use the policitally correct euphemism), "properties", built-in database and web servers, and all the other crud that's being added and has been sine 1.6 (and to a degree since 1.4 even, when some light at Sun decided that a built-in XML library would be a good thing despite the entire world already using another one).
> If you don't think it's confusing, you haven't realizes how truly complex they are.
I find them confusing, and I'm not sure I yet realize how complex they are. :o)
> Simplicity and a clean syntax is what makes Java a success, turning it into a mix of C++, Ruby, Python, and Visual Basic...
I tend to agree. With the advent of JRuby, Jython, Groovy, etc., that run on and are often tightly integrated with the Java platform, I don't see the need to have those features available in the Java language.
~
Flat View: This topic has 15 replies
on 2 pages
[
12
|
»
]