<< It's The People, Stupid! | Home | Comment On Alex Winston's Blog >>

It Looks Like I'm Not Alone

It looks like I'm not alone in wanting the Java closures syntax to be more Java methods like.

Both of the above, like mine, are non-proposals from non-language designers. And like mine, both appeal to the C function pointer syntax.

I understand that the C function pointer syntax is a little bit foreign to the non-C/C++ Java programmers. I still believe C function pointer syntax based Java closures syntax will mesh well with the rest of Java syntax.

For another reference point, here's the syntax for one of the C++ closure proposals:

tr1::function<int(bool)> A::f2 = int(bool b) { return b ? 1 : 2; };

Of course, for designers of the Java closure fetures, (I imagine) the syntax is the least important aspect of the design. Just like for those of us who writes GUI applications, we are not thinking about how good the screens are laid out when we are concentrating on the internals.

However, when they show their design to us, the syntax is the first thing that we have to get used to. Just like when we show a half baked GUI application to our users, the first thing they see is how ugly the screens are.

We are focusing on the syntax because that's all we see. And if my analogy can be carried a little further, the language designers don't usually know what the best syntax for the feature is. Just like the programmer usually design the ugliest GUIs.

Tags :


Re: It Looks Like I'm Not Alone

It's nice to know that I'm not alone either. I remember when Java first came out and everyone was raving and cheering about how pointers were deliberately left out of the language. But now we want first class methods in Java that accept other methods as parameters. To facilitate this we need to have the ability to pass around method references which are really just pointers to existing or anonymous methods (or blocks of code). To me it seems natural to want to use a pointer syntax for this purpose. So I too ask why we should not adopt the already familiar C/C++ pointer syntax for Java closures? Java did inherit most of its syntax from C++. When Java generics were added they too adopted the already familiar C++ template syntax. Why break the tradition?

Re: It Looks Like I'm Not Alone

In my proposal Clear, Consistent, Concise Syntax (C3S):

http://www.artima.com/weblogs/viewpost.jsp?thread=182412

You use the method keyword which I think is more Java like (unabbreviated keyword). Two examples in C3S are:

// In examples below MethodX are generic predefined interfaces in java.lang, they have a call method
// Keyword method, creates a MethodX
// () when calling a method are optional if unambiguous
// return is optional
// type is optionally inferred in variable and field declarations
// ; is optional before a }

final plus2 = method( Integer x ) { x + 2 };

public Method1<U, T> converter( Method0<T> a, Method0<U> b, Method1<U, T> c ) {  
  method( T t ) { a.call.equals( t ) ? b.call : c.call( t ) } 
}

Add a comment Send a TrackBack