Too terse and too alien?

Florian Weimer fweimer at bfk.de
Wed Jun 2 01:06:06 PDT 2010


* Alessio Stalla:

> Really? I forgot to mention no local variables, since Java doesn't have let.
> I can come up with reasonable counterexamples:
>
> sorting people by surname and name (middle name omitted for brevity :D):
>
> Collections.sort(people, #(Person p, Person q) (
>   p.getSurname().compareTo(q.getSurname()) != 0 ?
>   p.getSurname().compareTo(q.getSurname()) :
>   p.getName().compareTo(q.getName()) ));
>
> vs
>
> Collections.sort(people, #(Person p, Person q) {
>   int surnameComparison = p.getSurname().compareTo(q.getSurname());
>   return surnameComparison != 0 ? surnameComparison :
> p.getName().compareTo(q.getName())
> });

This is not a realistic example.  It will look more like this in
JDK 7:

 Collections.sort(people, mkComparator(Person#getSurname(), Person#getName()));

People will write combinator libraries soon to make this programming
style popular.

(I'm not sure about the exact syntax.)

> processing all event handlers in a list:
>
> Collections.map(list, #(EventListener e) {
>   try { e.handle(event); } catch(Exception e) { log.error("Exception
> while processing listener", e); }
> });

 Collections.map(list, suppressException1(e#handle(EventListener),
  #(Exception e) (log.error("Exception while processing listener", e))));

and so on.

-- 
Florian Weimer                <fweimer at bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstraße 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99


More information about the lambda-dev mailing list