Lambda the Ultimate

inactiveTopic 10 Reasons We Need Java 3.0
started 8/6/2002; 11:15:24 AM - last post 8/10/2002; 3:04:55 AM
Chris - 10 Reasons We Need Java 3.0  blueArrow
8/6/2002; 11:15:24 AM (reads: 1669, responses: 17)
This article imagines a "Java 3" that jettisons the baggage of the last decade, and proposes numerous changes to the core language, virtual machine, and class libraries. The focus here is on those changes that many people (including the Java developers at Sun) would really like to make, but can't -- primarily for reasons of backwards compatibility.

One author's feature requests for Java 3.0. I think the most interesting is "Eliminate primitive data types". I think that is one bit of "worse is better" legacy that Java could afford to drop. :-)

Adewale Oshineye - Re: 10 Reasons We Need Java 3.0  blueArrow
8/6/2002; 5:09:52 PM (reads: 1689, responses: 0)
Unfortunately this is highly likely to hurt Java's performance and memory utilisation. Besides if you don't want to use primitives you can make use of the wrapper classes.

There's also some discussion on this wiki page: http://c2.com/cgi/wiki?JavaThree which attempts to construct a more interesting list of changes for a hypothetical Java 3.

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 1:07:54 AM (reads: 1694, responses: 0)
Oh, make everything an object? You might want to read on Python's long journey towards this panacea.

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 3:59:51 AM (reads: 1683, responses: 2)

First I think a link to the article is required.

It's a bit funny to me that Elliotte Rusty Harold perceives his suggestions to be revolutionary, and thus continuously apologizes for them. While some of his suggestions may have significant repercussions on existing code, none of them appear revolutionary to me. For example, no mention of generics. At the very least he should look at Nice. I think Mr. Harold is so caught up in the Java frame of mind he can't see beyond that language's paradigm.

As to the suggestions on the wiki page, I'm all for closures (one of the main features I miss when programming in Java or C++), but all the examples given are of simple anonymous functions (except perhaps the use of isTheElementWeWant()). BTW, given Java's OOP nature, I think anonymous functions should actually be anonymous methods. That is, they should be methods of the same class as the method in which they are defined. This is so that they can access members of that class.

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 4:38:27 AM (reads: 1719, responses: 1)
I don't see how all these ideas interact. So I return an anonymous method from another method. It's a closure, and the client stores it somewhere. So the client must have an object of this class, in order to use the closure. Is this your model?

Maybe it makes sense to be able to create classes on the fly (even this is not all that revolutionary...)

Seems to me Java can learn a lot from other OOP/imperative languages (e.g., Ada, C++, Eiffel and even Python), before starting down the difficult path of integrating OOP and functional programming. [Indeed, I think Python does a nice job integrating some fp features, while remaining true to its original nature.]

Another way of looking at it: In the presence of fp features (hof, algebraic types, lazy evaluation etc.) it may be possible to streamline the language while keeping the basic OOP facilites. Simply adding features tends to make languages less consistent and usable.

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 7:12:57 AM (reads: 1676, responses: 1)
I don't see how all these ideas interact.

I don't think they do. This is indeed just a grocery list of useful features missing in Java. Obviously all these features exist in other languages, it's very hard to come up with a feature that doesn't, and I don't think Java wants to be that bleeding edge anyway.

Simply adding features tends to make languages less consistent and usable.

All too true, but it's a fact that Java is missing lots of useful mainstream features. Obviously common sense must be employed while adding such features, and they should be added in such a way as to preserve the spirit of the language.

Is this your model?

What I mean is that the anonymous method not only has access the variables in the scope it was defined (the closure), but also to members of the class in whose method it was defined. Indeed, I believe that this is more easily done, and more in conjunction with the spirit of Java than a real closure (after all Java doesn't even hane named functions, only methods). So in a first version (Java 3 as opposed to Java 4 :) you won't get real closure support, only anonymous methods (unfortunately you probably won't get either).

Maybe it makes sense to be able to create classes on the fly

Java already supports this (see the internal iterator sample in the wiki). As pointed out, however, the syntax is very verbose and a bit hard to read (which may explain C# using delegates instead).

Adewale Oshineye - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 7:33:39 AM (reads: 1775, responses: 0)
I'm not sure that the spirit of Java can absorb functional programming features. The spirit of Java is centred around being a better/simpler/cleaner version of C++. That's not necessarily a bad thing.

The trick is to find a set of additional features which preserve this spirit so that we end up with a better Java rather than Smalltalk-lite. The archetypal feature in this set would be something like generics: a relatively small change with significant benefits that doesn't compromise the conceptual integrity of the language.

So shopping lists of features that would transform Java into Smalltalk or Lisp or Eiffel are rather pointless because they aren't about improving Java but about replacing Java with some other language.

The harsh lesson to be learned from the success of Java (and possibly C#) is that if people in the mainstream wanted Smalltalk or Scheme (or even Python) they'd be using those languages. The best we can hope for is to smuggle some of the more useful fruits of academic research into the mainstream.

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 7:53:56 AM (reads: 1672, responses: 0)
I'm not sure that the spirit of Java can absorb functional programming features.

I'm not sure I can accept this statement as a given. For example, C++ did manage to absorb STL, which includes some functional tendencies. While it's true that C++ represents a more multi-paradigmatic approach than Java, the change was significant. I believe that the Java language and Java users can absorb changes provided they result in visible improvements and approachable code.

For example, looking at one of the samples in the wiki:

list.find(new Predicate() {
  public boolean isTrue(Object o) {
    return isTheElementWeWant(o);
  }
});

Wouldn't it look a lot nicer, even to a diehard Java programmer, if it could be written as:

list.find(boolean(Object o) {
  return isTheElementWeWant(o);
});

or something along these lines. Also note that initially only library writers would have to contend with the syntactic changes required to write to new list.find() method, other developers would simply enjoy it's simpler interface. Later this improvement would trickle down to the masses.

Several mainstream languages are (finally) moving in a functional direction, and it would be a mistake for Java to be left behind.

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 7:59:33 AM (reads: 1656, responses: 0)
BTW, the best way to write the sample above would obviously be:

list.find(isTheElementWeWant);

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 8:11:53 AM (reads: 1701, responses: 0)
To clarify, would the class-closure refer to the "current" object, would it only be able to refer to class-level fields ("static" in C++). or would it, like a regular method, need to be applied to a specific object?

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 8:24:13 AM (reads: 1647, responses: 1)
To tell the truth, this isn't a concept I have fully designed in my head. I'm sort of thinking this out on the fly. For example, I'm not sure what the syntax should be for defining references to methods should be (that is, how list.find() sig should look like). But to answer your question, I think the class-closure should refer to the "current" object. This obviously raises the question of what should happen if this code is used in a static (class-level) method. In that case, the anonymous method should also be static. But then, should we have two versions of list.find() or should a single instance handle both? It seems we should have only one because list.find() doesn't really care, but that could be difficult for the compiler to handle.

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 8:32:42 AM (reads: 1693, responses: 0)
But what if the current object (at the time the closure is taken) ceases to exist?

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 8:42:24 AM (reads: 1637, responses: 1)
Since the method reference hold a reference to the object (the 'this' value), how can this happen?

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 8:46:31 AM (reads: 1696, responses: 0)
(Now you are talking GC. I was talking scope.) I thought this is what you are going to say. Perhaps this is the Right Thing. Still, I don't like it...

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 9:01:11 AM (reads: 1657, responses: 2)

I agree that class-closure is a poor replacement for real closures. What I was saying is:

  1. Java can benefit from both. In fact if you provide scope closure you probably need class-closure as well (you might even get it automatically through the value of 'this').
  2. Class-closure would require less changes to the language and the JVM and is better than nothing
Still, I don't like it...

But you don't really like Java anyway. I have to say that this exchange is becoming almost like a chat :-)

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 9:29:26 AM (reads: 1688, responses: 1)
Well, chats can sometime be fun...

It's strange you know I don't like Java. I tend not to talk about Java much, since I am not really an expert. I never built anything compilcated using Java, and I don't really want to learn all the intericate details of the language.

So it's not really that I don't like Java, it's more that I never liked to study it properly

Dan Shappir - Re: 10 Reasons We Need Java 3.0  blueArrow
8/7/2002; 9:58:20 AM (reads: 1732, responses: 0)
I'm currently heavily into Java because the company I work for is building a server application that needs to be platform independent. Given the platforms we need to support, the background of most of our developers, and the available tools, Java seems the natural choice.

Working with Java is OK, though I'm not balled over. Standard OOP stuff (and the standard problems where some developers think they know OOP but really don't, e.g. lots of static functions). I am missing generics, let me tell you. And closures (which I don't have in C++, my other main language, either) though inner-classes are better than nothing. I am playing with Nice, but I can't imagine we will be using it for any major development any time soon.

Ah yes, and speaking of Nice, Java should also have touples, given that it doesn't support output parameters.

Ehud Lamm - Re: 10 Reasons We Need Java 3.0  blueArrow
8/10/2002; 3:04:55 AM (reads: 1600, responses: 0)
I'm not sure that the spirit of Java can absorb functional programming features.

>>>I'm not sure I can accept this statement as a given. For example, C++ did manage to absorb STL

C++ was designed to be a multi-paradigmatic language. I am not sure the same can be said about Java.