[Pitch] Align label behavior for subscripts

This is probably something additional and it might already have been discussed here somewhere, I apologize if I missed that talk.

The rule for parameter labels on functions was fixed in Swift, but now it kinda feels odd to have a different pair of rules for subscripts (at least it does feel odd to me).

// Is fine when the names are different
subscript(externalName internalName: ParamType) -> ElementType {
    get { … }
    set { … }
}

something[externalName: …]

// We had this with functions already, remeber?
subscript(sameName sameName: ParamType) -> ElementType {
    get { … }
    set { … }
}
Aligning this wouldn’t break anything. I believe this can be migrated easily.

// No label!
subscript(_ internalName: ParamType) -> ElementType {
    get { … }
    set { … }
}

something[externalName: …]

// Label name is the same as the parameter name
subscript(sameName: ParamType) -> ElementType {
    get { … }
    set { … }
}

// Different names
subscript(externalName internalName: ParamType) -> ElementType {
    get { … }
    set { … }
}
I know this might be something for stage 2, and I apologize again for posting this early, but we need a better way to keep ideas alive and not forget them after a half of a year. ;) (Forum?)

···

--
Adrian Zubarev
Sent with Airmail

2 Likes

This is probably something additional and it might already have been discussed here somewhere, I apologize if I missed that talk.

The rule for parameter labels on functions was fixed in Swift, but now it kinda feels odd to have a different pair of rules for subscripts (at least it does feel odd to me).

FWIW, operator functions, e.g.,

  func +(lhs: Int, rhs: Int) -> Int

have the same rule as subscripts.

Personally, I don’t want to ever revisit these rules again. They’ve changed with every major Swift release, and I feel that we’ve landed in the right place.

I agree.

-Chris

···

On Sep 20, 2016, at 5:42 AM, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Sep 20, 2016, at 3:36 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

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

FWIW, operator functions, e.g.,

  func +(lhs: Int, rhs: Int) -> Int

have the same rule as subscripts.

Personally, I don’t want to ever revisit these rules again. They’ve changed with every major Swift release, and I feel that we’ve landed in the right place.

  - Doug

···

On Sep 20, 2016, at 3:36 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

This is probably something additional and it might already have been discussed here somewhere, I apologize if I missed that talk.

The rule for parameter labels on functions was fixed in Swift, but now it kinda feels odd to have a different pair of rules for subscripts (at least it does feel odd to me).

I agree, no obvious win to revisiting, best to keep source compatibility.

···

On Tue, Sep 20, 2016 at 10:43 Douglas Gregor via swift-evolution < swift-evolution@swift.org> wrote:

On Sep 20, 2016, at 3:36 AM, Adrian Zubarev via swift-evolution < > swift-evolution@swift.org> wrote:

This is probably something additional and it might already have been
discussed here somewhere, I apologize if I missed that talk.

The rule for parameter labels on functions was fixed in Swift, but now it
kinda feels odd to have a different pair of rules for subscripts (at least
it does feel odd to me).

FWIW, operator functions, e.g.,

func +(lhs: Int, rhs: Int) -> Int

have the same rule as subscripts.

Personally, I don’t want to ever revisit these rules again. They’ve
changed with every major Swift release, and I feel that we’ve landed in the
right place.

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

It sounds like they were a joy to handle under the hood... yikes ;).

···

Sent from my iPhone

On 20 Sep 2016, at 16:42, Douglas Gregor via swift-evolution <swift-evolution@swift.org> wrote:

On Sep 20, 2016, at 3:36 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:

This is probably something additional and it might already have been discussed here somewhere, I apologize if I missed that talk.

The rule for parameter labels on functions was fixed in Swift, but now it kinda feels odd to have a different pair of rules for subscripts (at least it does feel odd to me).

FWIW, operator functions, e.g.,

  func +(lhs: Int, rhs: Int) -> Int

have the same rule as subscripts.

Personally, I don’t want to ever revisit these rules again. They’ve changed with every major Swift release, and I feel that we’ve landed in the right place.

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