[swift-evolution] [SHORT Review] SE-0132: Rationalizing Sequence end-operation names

Nevin Brackett-Rozinsky nevin.brackettrozinsky at gmail.com
Tue Jul 26 18:16:17 CDT 2016


>
> * We considered using `first` and `last` as the basis for both
>    single-element and multiple-element operations (such that `prefix(3)`
>    would become `first(3)`, etc.), but:
>


   1. These seemed like distinct functionalities, particularly since
>       their types are different.


I think the functionality of “Please give me the first 1 element” is
extremely similar to “Please give me the first n elements”.




Keeping those issues in mind, do you still prefer `first(n)` over
> `prefix(n)`?


In my subjective opinion, `.first`, `.first(n)`, and `starts(with: [1, 2,
3])` are crystal-clear at the use site, and coexist just fine.
Additionally, `hasPrefix([1, 2, 3])` is equally clear and I would be fine
with that—in particular I am fine with the “get” and “test” methods using
different words.

By contrast, I find `prefix(n)` to be unclear about the role of `n`.
Something like `prefix(limit: n)`


On Tue, Jul 26, 2016 at 3:46 PM, Brent Royal-Gordon <brent at architechies.com>
wrote:

> > On Jul 26, 2016, at 8:30 AM, Nevin Brackett-Rozinsky <
> nevin.brackettrozinsky at gmail.com> wrote:
> >
> > However, I believe that `first(n)` and `last(n)` read more clearly at
> the point of use than `prefix(n)` and `suffix(n)`.
>
> I've seen this a couple of times. It's something I bring up in "Other
> alternatives":
>
> > * We considered using `first` and `last` as the basis for both
> >   single-element and multiple-element operations (such that `prefix(3)`
> >   would become `first(3)`, etc.), but:
> >
> >   1. These seemed like distinct functionalities, particularly since
> >      their types are different.
> >
> >   2. We're not comfortable with heavily overloading a property with a
> >      bunch of methods, and didn't want to make `first` and `last` into
> >        methods.
> >
> >   3. Most APIs work fine, but `hasFirst(_:)` is atrocious, and we see
> >      no better alternative which includes the word `first`.
>
> To give you an idea of what I mean by #3:
>
>         if numbers.hasFirst([1, 2, 3, 4, 5]) && numbers.hasLast([5, 4, 3,
> 2, 1]) { … }
>
> Keeping those issues in mind, do you still prefer `first(n)` over
> `prefix(n)`?
>
> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160726/df6243c6/attachment.html>


More information about the swift-evolution mailing list