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.
- Pointer Syntax for Java Closures (WarpedJavaGuy)
int y = 6; boolean* (int) a = (int x) {x <= y}; boolean* (int) b = (int x) {x >= y}; boolean c = a.invoke(3) && b.invoke(7); - Closure Syntax (Alex Winston)
int plus2(int) = int (int x) { return x + 2; };
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.
Re: It Looks Like I'm Not Alone
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 ) }
}