Two small points of feedback

Zhong Yu zhong.j.yu at gmail.com
Fri Jan 4 08:37:16 PST 2013


Is "inclusive" range very useful in Java ecosystem? Maybe for simple,
literal ranges; for other cases it's probably clunkier

    rangeInc(off, off+len-1)  vs rangeExc(off, off+len)

"Exclusive range" probably should be the default since it's the
established convention, it interoperates well with other codes, and
won't cause problems for any C-family programmers.

If someone writes a literal range like rangeInc(1,10), instead of
rangeEx(0,10), he's probably not observing the convention, and he'll
soon run into problems with the rest of Java world.

(I'm even against providing an option for inclusive range; converting
between inclusive/exclusive ranges is something that should be very
simple, yet somehow is disorienting to human minds, like daylight
saving time transition. Life is simpler if everybody sticks to 1
convention)

Zhong Yu

On Fri, Jan 4, 2013 at 9:49 AM, Stephen Colebourne <scolebourne at joda.org> wrote:
> On 4 January 2013 15:05, Brian Goetz <brian.goetz at oracle.com> wrote:
>>> 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.
>>
>> And what about
>>
>>   string.substring(0, 10)
>> or
>>   Arrays.sort(a, 0, 10)
>>
>> or...?   These have discrete numbers too.
>
> These are indices into a list/array/string. Range defines the set of
> ints themselves. These is related but not entirely the same. (indices
> point at the gaps between things, a range of ints points at the things
> themselves). So, yes, I think there is a conceptual difference.
>
> I believe you need two methods. One of these three options:
> - rangeInclusive()
> - rangeExclusive()
>
> - range()
> - rangeExclusive()
>
> - range()
> - rangeInclusive()
>
> I don't currently have a strong preference between them.
>
> I don't support a boolean flag on range() as that is meaningless. An
> enum would be too verbose IMO.
> Stephen
>


More information about the lambda-dev mailing list