danceboy: (lyra)
[personal profile] danceboy
Does anyone know why it is that in Java 8 List.replaceAll doesn't return the list in question (post replacement (or even better, with lazy evaluation waiting to happen))?

That asked, going back before java 8, does anyone know why List.add doesn't return the list? I think the official reason is so that it can always return true so as to implement Collection.list. But that's kind of terrible...

I mean is there a bad reason, or just no reason at all? The entire point of java 8 lambdas is to reduce the amount you have to type...

I'd like this:
   System.out.println(new LinkedList().add(1).add(2).replaceAll(i -> i*i).add(3));

to generate this:
   [1,4,3]

Instead I have to do this:
   List list = new LinkedList<>();
   list.add(1);
   list.add(2);
   list.replaceAll(i -> i*i);
   list.add(3);
   System.out.println(list);

Is there some java 8 thing I haven't seen yet that might improve this?

Date: 2014-05-24 11:06 pm (UTC)
From: [identity profile] metahacker.livejournal.com
Java subscribes to what is technically known as the "illiterate" programming style, also sometimes called COBOL-fingers. ("Why use ten characters when twenty would do?")

Date: 2014-05-25 12:42 am (UTC)
From: [identity profile] danceboy.livejournal.com
Well, yes, but lambdas are specifically an attempt to get away from that. They offer no new functionality at all; they're just syntactic sugar for anonymous inner classes.

I'm not sure if I should be claiming to be old and to have grown up with lisp, and "all you kids today", or if I should be claiming to be young, and how I actually have seen a real live functional language in the wild...

Date: 2014-05-25 02:28 am (UTC)
From: [identity profile] metahacker.livejournal.com
Each new generation has to re-encounter LISP, feels like. Literally having this conversation over in my journal with [livejournal.com profile] squirrelitude...

I think you were right when you said it was to fulfill the contract of Collection. But that's no excuse not to add a convenience method which returns 'this'.

Profile

danceboy: (Default)
danceboy

October 2017

S M T W T F S
1234567
8910111213 14
15161718192021
22 232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 25th, 2026 07:06 pm
Powered by Dreamwidth Studios