API design: (start,length) vs (start,end)
Kevin Bourrillion
kevinb at google.com
Tue Nov 20 10:43:33 PST 2012
It's "delightful" that classes like
Writer<http://docs.oracle.com/javase/6/docs/api/java/io/Writer.html>
have
even wound up with methods of both styles right in the same class.
I've never been quite able to "solve" this issue, but I would note that
from/length is a lot more, shall we say, "streamy" in nature than from/to.
On Tue, Nov 20, 2012 at 10:23 AM, Per Bothner <per at bothner.com> wrote:
> The Java APIs have many methods that select a slice of a
> sequence or an array, but there is no consistency as to
> how to specify the slice: Many places uses (fromIndex,
> toIndex), and many other places uses (fromIndex,length).
>
> Specifically, I notice that java.util.streams.Streams uses
> (fromIndex,length), while *older* methods in java.util.Arrays
> use (fromIndex, toIndex), but the newly added ones use
> (fromIndex,length).
>
> This inconsistency is unfortunate. As mentioned the Java APIs
> are already inconsistent, so to some extent we just have to
> live with it, but the inconsistency within the Arrays class
> seems extra unfortunate.
>
> Was there a considered decision to use (fromIndex,length)
> instead of (fromIndex,toIndex) in new methods? When designing
> my own APIs is there any reason to choose one or the other?
> --
> --Per Bothner
> per at bothner.com http://per.bothner.com/
>
>
--
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
More information about the lambda-dev
mailing list