[swift-evolution] Fwd: [Draft] Rationalizing Sequence end-operation names

Dave Abrahams dabrahams at apple.com
Fri Jul 1 17:53:48 CDT 2016

on Thu Jun 23 2016, Xiaodi Wu <swift-evolution at swift.org> wrote:

> Yikes, not only is the email too big for some mail clients, it's too big
> for the mailing list. Resending with proposal snipped.
> On Thu, Jun 23, 2016 at 1:24 PM, David Hart via swift-evolution <
> swift-evolution at swift.org> wrote:
>> Most of your proposal look great to me! Comments inline:
>> On 23 Jun 2016, at 09:19, Brent Royal-Gordon via swift-evolution <
>> swift-evolution at swift.org> wrote:
>> As previously threatened mentioned, I've written a draft proposal to fix
>> a number of naming issues with APIs operating on the beginning and end of
>> Sequences and Collections:
>> • Inconsistent use of `prefix`/`suffix` vs. `first`/`last`
>> • Confusing naming of `drop` methods
>> • Ambiguous naming of `index(of:/where:)` and `drop(while:)`
>> • `prefix(upTo:)`, `prefix(through:)`, and `suffix(from:)` shouldn't be
>> part of this family at all
>> To fix this, I propose:
>> • Renaming all methods which operate on more than one element at the
>> beginning/end to use "prefix" or "suffix", not "first" or "last"
>> Looking at the first column in your table, I think the current API focuses
> correctly on the number of elements returned (and consequently, the return
> type) rather than the number of elements interrogated. "First" and "last"
> on their own suggest very strongly that you get back either zero elements
> or one element (thus, an optional would be the appropriate return type),
> whereas "prefix" and "suffix" suggest 0 to all elements might be returned
> (thus, an array or collection would be the appropriate return type).
> Currently, the API adheres to that expectation as far as your "get" column
> is concerned, and IMO the most consistent approach would be to whip the
> remaining columns in line.
> To me, `first(where:)` is unambiguous and doubly distinguished from
> `prefix(while:)`--even when the argument label is dropped in trailing
> closure syntax, it is clear that `first` gives you at most one, and by
> contradistinction `prefix` gives you at most all. I'm not sure that
> "earliest" is an improvement, since you're introducing another word and
> breaking the parallels here. So on reflection, I'm satisfied that first,
> prefix, last, suffix all have their place in the API. Of course, I think
> you could make a case for an across-the-board renaming of "first" to
> "earliest" and "last" to "latest"--in fact, there could be an argument that
> given 0-based indices the word "first" is an unfortunate choice in any
> case.

Now it's my turn to call someone else overly fussy ;-).

People commonly talk about the first element of an array, and “earliest”
could even be confusing depending on context:

   let a = [ now(), tomorrow(), yesterday() ]


More information about the swift-evolution mailing list