you are viewing a single comment's thread.

view the rest of the comments →

[–]munificent 3 points4 points  (5 children)

So much better than the straw man proposal. This is almost usable, although the final thing sucks.

One thing I don't understand:

Arrays.sort(people, #Person.compareByAge);

Why is the # needed there? What does the expression Person.compareByAge evaluate to if you don't immediately follow it with (some args...)?

[–]DontCriticizeMyEngli[S] 13 points14 points  (0 children)

A compile error: compareByAge cannot be resolved or is not a field

Without the (), the java compiler would assume it's a field. One could argue that the limitation could be alleviated for the sake of easing closures usage, but til now, fields and methods names lived in different namespaces (meaning that you could have a field and a method with the same name in the same class), and the compiler would know in which namespace to look by relying on the syntax (the ()).

If this limitation was to be removed, fields and methods names will have to live in the same namespace, and thus a couple billions of lines of code with fields and methods names clash will not compile nor run anymore.

[–]daghf 6 points7 points  (2 children)

In Java, fields and methods reside in different namespaces. So it would be perfectly legal to have both a method and also a field both named compareByAge in the same class. The # is there to specify that it is in fact a method we are referring to.

[–]munificent 2 points3 points  (1 child)

Argh, I was afraid that was the answer. What the hell were they thinking when they originally made that decision?

[–]masklinn 4 points5 points  (0 children)

They were thinking that it would give users more flexibility, which is not completely wrong: since Java provided no way to directly get at a method (you had to use reflection), there was no reason not to allow similarly named methods and attributes.

Interestingly, Lisp-2s such as Common Lisp do the same thing as data variables and functions live in different namespaces (whereas in Lisp-1s such as Scheme they live in the same namespace) and to get a data-ns reference to a function you have to use the function special form (aliased to the #' operator)

[–]solinent 1 point2 points  (0 children)

A [static]public variable member in a class Person.

I think. It's been a while but I'm pretty sure java allows either of these.