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

Anders Ha hello at andersio.co
Thu Jun 23 12:18:41 CDT 2016

> On 23 Jun 2016, at 3:19 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org <mailto: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"

Just want to point out that `prefix` and `suffix` may introduce ambiguity, as they are also imperative verbs. For example, `S.prefix(1)` can be inferred as prefixing `1` to the sequence, instead of retrieving the prefix of the sequence.

IMO `skip`, as an alternative listed in the proposal, would convey the intention better and clearer, and it has roots in the sequence-like constructs of reactive programming libraries (e.g. RxSwift and ReactiveCocoa).

> • Renaming `index(of:/where:)` to `earliestIndex(…)` and `first(where:)` to `earliest(where:)`
> • Renaming the `drop` methods to use `removing`
> • Redesigning `prefix(upTo:)`, `prefix(through:)` and `suffix(from:)` as subscripts with "partial" ranges, like `people[..<idx]` or perhaps `people[nil..<idx]`.
> Since that last point requires significant redesign, including the introduction of new types, I have also included an alternative design which uses `people[to: idx]` instead.
> This proposal does not seek to add new functionality; it merely renames or (in the case of the "aggressive" subscript option) redesigns existing functionality. I do, however, discuss (without making many judgements about their wisdom) how these changes might affect the naming of functionality we might add in future versions of Swift.
> I would mainly like feedback on the two most open questions left in this proposal:
> • The choice of `removing` to replace `drop`
> • The decision about whether to use `people[..<idx]`, `people[nil..<idx]`, or `people[to: idx]`.
> But I'd also like comments on the rest of the proposal, and on whether I should split the prefix(upTo:/through:)/suffix(from:) changes into a separate proposal from the rest.
> I suspect this will cause a firestorm of bikeshedding, so please try to keep your suggestions grounded. Don't just suggest a name; articulate why it's a better choice than what we already have or what this proposal suggests. Only you can prevent our first *three*-hundred-message bikeshedding thread.
> Thanks for your attention!
> (P.S. The proposal below includes several huge tables which may cause some mail clients to become very pouty and refuse to eat their supper. You may want to read the proposal at <https://gist.github.com/brentdax/024d26c2b68b88323989540c06261430 <https://gist.github.com/brentdax/024d26c2b68b88323989540c06261430>> instead.)
> -- 
> Brent Royal-Gordon
> Architechies
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160624/df0face8/attachment.html>

More information about the swift-evolution mailing list