[Review] SE-0065 A New Model for Collections and Indices


(Patrick Smith) #1

+1 to Tony’s naming suggestions, myself preferring move(index:by:),
move(indexForward:), and move(indexBackward:) as it is the most clear and
consistent.

As an aside, I am not a fan of the form- prefix, as it feels generic without
being self explanatory. I think another word would work better. I won’t
bikeshed, but I feel form- feels and reads oddly every time I see it.

> On Apr 10, 2016, at 2:41 PM, Chris Lattner via swift-evolution &lt

;[swift-evolution@swift.org](mailto:swift-evolution@swift.org "mailto:swift-
evolution@swift.org" )> wrote:
>
> Hello Swift community,
>
> The review of "A New Model for Collections and Indices" begins now and
runs through April 18th. The proposal is available here:
>
&gt; <https://github.com/apple/swift-evolution/blob/master/proposals/0065
-collections-move-indices.md>[
](https://github.com/apple/swift-evolution/blob/master/proposals/0065
-collections-move-indices.md "https://github.com/apple/swift-
evolution/blob/master/proposals/0065-collections-move-indices.md" )&gt;
&gt; Reviews are an important part of the Swift evolution process. All reviews
should be sent to the swift-evolution mailing list at:
&gt; <https://lists.swift.org/mailman/listinfo/swift-evolution>[
](https://lists.swift.org/mailman/listinfo/swift-evolution
"https://lists.swift.org/mailman/listinfo/swift-evolution" )&gt; or, if you
would like to keep your feedback private, directly to the review manager.
&gt;
&gt;
&gt; What goes into a review?
&gt;
&gt; The goal of the review process is to improve the proposal under review
through constructive criticism and, eventually, determine the direction of
Swift. When writing your review, here are some questions you might want to
answer in your review:
&gt;
&gt; * What is your evaluation of the proposal?

I agree with the general direction and scope of the proposal, but I think

the names could use some changes. Specifically, I don’t think the fallback to
‘form’ is required. It would be a significant readability improvement to use a
meaningful verb to describe the action of altering the argument. The methods
that create new indices probably need a label on the first argument, because
otherwise it looks as if the IndexDistance is what is described by ‘index’.

Proposed:

  func successor(of i: Index) -&gt; Index

  func formSuccessor(i: inout Index)

Instead, I suggest:

  func successor(of i : Index) -&gt; Index

  func advance(i: inout Index)

Proposed:

  func index(n: IndexDistance, stepsFrom i: Index) -&gt; Index

  func index(n: IndexDistance, stepsFrom i: Index, limitedBy limit: Index)

-&gt; Index

  func formIndex(n: IndexDistance, stepsFrom i: inout Index)

  func formIndex(n: IndexDistance, stepsFrom i: inout Index, limitedBy

limit: Index)

Suggested (taking into account Nate’s suggestion of reversing the order):

  func index(startingAt i: Index, movedBy n: IndexDistance) -&gt; Index

  func index(startingAt i: Index, movedBy n: IndexDistance, limitedBy limit:

Index) -&gt; Index

  func move(i : inout Index, by n: IndexDistance)

  func move(i : inout Index, by n: IndexDistance, limitedBy limit: Index)

Proposed:

  func predecessor(of i: Index) -&gt; Index

  func formPredecessor(i: inout Index)

Suggested:

  func predecessor(of i: Index) -&gt; Index

  func reverse(i: inout Index)

I think reversing an index has some nice symmetry with reversing a sequence,

but if it seems to confusing, then replace advance and reverse with
‘moveForward’ and ‘moveBackward’.

···

\- Tony


(Dave Abrahams) #2

+1 to Tony’s naming suggestions, myself preferring move(index:by:), move
(indexForward:), and move(indexBackward:) as it is the most clear and
consistent.

Sure, any individual operation in a mutating/nonmutating pair can be
better named if you don't consider how to name the corresponding
operation such that the names preserve the relationship. How do you
name the nonmutating versions of these?

As an aside, I am not a fan of the form- prefix, as it feels generic
without being self explanatory. I think another word would work
better.

Yeah, practically everybody including me has the same feeling: there's
probably a better answer out there. Problem is, what is it? [There's a
better pair of words, except that we can't use those].

I won’t bikeshed,

Please, be my guest and bikeshed. It's more useful to come up with
alternatives than to simply state dissatisfaction with the status quo.

···

on Tue Apr 12 2016, Patrick Smith <swift-evolution@swift.org> wrote:

but I feel form- feels and reads oddly every time I see it.

    > On Apr 10, 2016, at 2:41 PM, Chris Lattner via swift-evolution > <swift-evolution@swift.org> wrote:
    >
    > Hello Swift community,
    >
    > The review of "A New Model for Collections and Indices" begins now and
    runs through April 18th. The proposal is available here:
    >
    >
    https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices.md

    >
    > Reviews are an important part of the Swift evolution process. All reviews
    should be sent to the swift-evolution mailing list at:
    > https://lists.swift.org/mailman/listinfo/swift-evolution
    > or, if you would like to keep your feedback private, directly to the
    review manager.
    >
    >
    > What goes into a review?
    >
    > The goal of the review process is to improve the proposal under review
    through constructive criticism and, eventually, determine the direction of
    Swift. When writing your review, here are some questions you might want to
    answer in your review:
    >
    > * What is your evaluation of the proposal?

    I agree with the general direction and scope of the proposal, but I think
    the names could use some changes. Specifically, I don’t think the fallback
    to ‘form’ is required. It would be a significant readability improvement to
    use a meaningful verb to describe the action of altering the argument. The
    methods that create new indices probably need a label on the first argument,
    because otherwise it looks as if the IndexDistance is what is described by
    ‘index’.

    Proposed:

    func successor(of i: Index) -> Index

    func formSuccessor(i: inout Index)

    Instead, I suggest:

    func successor(of i : Index) -> Index

    func advance(i: inout Index)

    Proposed:

    func index(n: IndexDistance, stepsFrom i: Index) -> Index

    func index(n: IndexDistance, stepsFrom i: Index, limitedBy limit: Index) ->
    Index

    func formIndex(n: IndexDistance, stepsFrom i: inout Index)

    func formIndex(n: IndexDistance, stepsFrom i: inout Index, limitedBy limit:
    Index)

    Suggested (taking into account Nate’s suggestion of reversing the order):

    func index(startingAt i: Index, movedBy n: IndexDistance) -> Index

    func index(startingAt i: Index, movedBy n: IndexDistance, limitedBy limit:
    Index) -> Index

    func move(i : inout Index, by n: IndexDistance)

    func move(i : inout Index, by n: IndexDistance, limitedBy limit: Index)

    Proposed:

    func predecessor(of i: Index) -> Index

    func formPredecessor(i: inout Index)

    Suggested:

    func predecessor(of i: Index) -> Index

    func reverse(i: inout Index)

    I think reversing an index has some nice symmetry with reversing a sequence,
    but if it seems to confusing, then replace advance and reverse with
    ‘moveForward’ and ‘moveBackward’.

    - Tony

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
Dave