Syntax poll, take 2

Jakob Praher jp at hapra.at
Mon Jun 13 13:13:16 PDT 2011


Hi folks,

as a spare time lurker, I am still not sure I buy the small lambda
because of anonymous classes argument yet. Though it is a good point.
There are a lot of cases (the single method interfaces/ classes) where a
concise syntax is also important for 'big lambdas'. In C# land AFAIK you
always had delegates (I know that this was a much debated issue between
MS "J++" and Sun's Java once [1]). But when seeing it from C# this
argument makes much more sense (because you have anonymous delegates).

Just as an exampe of the signal to noise ratio when using singly method
anonymous inner classes (not wanting to talk about whether this is yet
another example for a small lambda, since it really depends on the
filter algorithm you use - and in Java things quickly get more than one
line of code (which does not imply it is bad):

File.list(new FilenameFilter() {
boolean accept(File dir, String name) {
   ...
}
});

So my conjecture is: Once lambdas are available and usable (from a
library point of view), people will introduce them to do more than just
single lines of code, also for the above signal noice ratio.

And the mentioned Ruby syntax (for blocks as they call them) is totally
another point since Ruby allows you to put the lambda as a postfix
'operator' , thus enables you to write:

File.list {
   | dir, name |
   ...
}

which is _way_ better!

Also people that heavily use Javascript can tell you how annoying the
trailing ')' after the curly brace can be ( });).

Just my 2 cents,
Jakob

[1] =
http://webcache.googleusercontent.com/search?q=cache:5iGFhb7sgx8J:java.sun.com/docs/white/delegates.html+delegates+sun.com&cd=1&hl=de&ct=clnk&gl=at&client=firefox-a&source=www.google.at

Am 13.06.11 20:20, schrieb Neal Gafter:
> On Mon, Jun 13, 2011 at 9:30 AM, Reinier Zwitserloot <
> reinier at zwitserloot.com> wrote:
>
>> The instructions include examples, but these examples are rather unlikely
>> to
>> be representative of what Joe Java is _ever_ going to write. Anyone filling
>> in this poll based primarily on looking at them is going to make an
>> uninformed decision.
>>
>> All examples in the instructions share 2 properties:
>>
>> (A) They are a single expression.
>>
>> (B) They are written as a physical single line. (one-liner).
>>
> My experience with C# - and particularly with the aggregate-data operations
> that are a prime motivator for project lambda - is that the majority of
> lambdas are indeed single-expression ones.  That's why I prefer a syntax
> similar to C#'s (which, incidentally, did not appear among the choices):
>
> () -> expression
> () -> { statements }
> id -> expression
> id -> { statements }
> ( paramList ) -> expression
> ( paramList ) -> { statements }
>
> I believe that if project Lambda does a good job, the experience of Java
> (e.g. the distribution of sizes of lambda expressions) will be similar to
> that of C#.  For that to come about it must be easy and natural to write
> code using bulk data operations.
>
> The really-simple lambda expressions (e.g. bulk data operations) are the
> ones where project Lambda has an opportunity to make the most difference
> compared to anonymous inner classes.  If the body is already 10-20 lines, a
> lambda isn't much better than an anonymous inner class.  But for really
> small ones, it is the friction of the anonymous inner class syntax that
> really makes that style of programming tedious.  The more concise the lambda
> syntax, the easier those cases become.
>
> Cheers,
> Neal
>



More information about the lambda-dev mailing list