Two small points of feedback
Stephen Colebourne
scolebourne at joda.org
Fri Jan 4 06:59:58 PST 2013
On 4 January 2013 14:49, Brian Goetz <brian.goetz at oracle.com> wrote:
>> 1) "What does this code do"
>>
>> range(1, 10).forEach( (i) -> System.out.println(i) );
>
>
> Why would this be different from:
>
> for(int i=0; i<10; i++)
> println(i);
>
> Or from the numerous methods that take half-open (start, end) pairs, like
> String.substring?
I get this point. And I think the experienced Java developers did too
(we've all been bitten by off-by-one errors).
But I think if you look at the code in isolation, with no previous
knowledge of lambdas, you see "1", "10", "foreach" and assume 1 to 10
inclusive. (A good thing to test further in a poll or user focus
group)
My theory is that its because the numbers are discrete. "From Monday
to Wednesday" is closed in normal language, whereas "from 09:00 to
17:00" is not. Similarly "the TV channels 1 to 4" is closed, but "from
1.3 to 8.6" is more likely to be half-open.
My second theory is that its because the example uses "1", rather than
"0". range(0, 10) may have elicited different answers.
Of course in "for(int i=0; i<10; i++)", its pretty clear that it is
less than 10.
Stephen
More information about the lambda-dev
mailing list