> > list -> filter( test1 ) -> filter( test2 ) -> sort(); > > > > Reads better than: > > > > sort( filter( filter( list, test1 ), test2 ) ); > > Personally, I like the second format better.
You know, maybe all this "Ruby/Scala/Python can do that in 1 line of code" is making Java panic. Including myself - I do tend to write terser code than my colleagues. While I strongly prefer the 1st format cause I never did much LISP programming, IMO the best layout by far is still
List temp1 = filter( list, test1 );
List temp2 = filter( temp1, test2 );
sort( temp2 );
Assuming that you don't want the intermediate terms then the -> form is clearer and shorter and easier to get right (you will pass the correct first argument to filter). The functional form is also short and doesn't need the intermediates but reads inside out instead of left to right and most people prefer left to right.
But sure, these readability points aren't to me show stoppers - I think you would need many people to be keen for this to be a worthwhile addition to Java.
Flat View: This topic has 16 replies
on 2 pages