Readability
Brian Goetz
brian.goetz at oracle.com
Wed Dec 22 10:25:03 PST 2010
We definitely think readability is important. (That's part of the reason
we're doing this at all; you can use inner classes today for a lot, but one of
their problems is that they're visually clunky.)
Don't forget the power of whitespace to make things more readable.
List<String> sorted =
people.select(#{p->p.getFirstName()}).where(#{p->p.length <
10}).orderBy(#{p->p.length});
Could be (just by introducing some line breaks):
List<String> sorted =
people.select(#{p->p.getFirstName()})
.where(#{p->p.length < 10})
.orderBy(#{p->p.length});
That's already a lot more readable; even if the lambda expressions are
gibberish, the shape of the code (project/filter/sort) has already emerged.
Better use of spaces helps even more:
List<String> sorted =
people.select( #{ p -> p.getFirstName() } )
.where( #{ p -> p.length < 10 } )
.orderBy( #{ p -> p.length } );
(Your taste may vary about where you want to put the spaces, and I'm not
saying this is the "one true alignment style", but you can't deny that this is
more readable than just stringing it all together.)
More information about the lambda-dev
mailing list