Brevity
Thoughts about introducing closures in Java has definitely been triggerred by the excellent support of closures provided by C# and the host of scripting languages like Ruby, Groovy, Python and Javascript. The syntax, as proposed in the draft looks a bit cumbersome to me, particularly after getting used to the elegance of Groovy, Ruby and even C#. I know Java, being a statically typed language does not help in making the closure syntax as elegant as dynamic languages.
My Wishlist of Associated Features
If closures see the light of the day in Java, then, I would like to have the following associated features, which will make the set more complete :
- Type aliasing / typedefs : Without type aliasing it will be extremely cumbersome to write the entire type signature everytime. I am sure this will also make programming with generics much easier. The keyword is *syntax-brevity* and type aliasing is a great way to achieve it.
- Currying : Higher order functions and closures are definitive steps towards implementing full currying features.
- Generic Closures : It will be interesting to find out how closures will mix with generics.
- Internal Iterators : I would love to write code like the following:
int[] list = ...
int[] evens = Arrays.findAll(list, (int n) { return n % 2 == 0; });
No comments:
Post a Comment