[Proposal] Shorthand Argument Renaming


(James F) #1

Moreover, this would free up $ as an operator. I'm for removing it.

I'm not sure about #n, since all code is ‘compiler magic’ when it gets down to it, but this feature is commonly used enough that I don't think edge-case syntax is appropriate. Newcomers to the language would read #2 as ‘argument number 2’ (with hash being used as a number sign), diluting the meaning somewhat.

I'm leaning towards .n, since these are contextual values.

------------ Begin Message ------------
Group: gmane.comp.lang.swift.evolution
MsgID: <D63CF3BB-A278-4428-82CA-6D47AA02426A@douwere.com>

This was the point : $ has precedent in unix shell programming with one-based counting, and zero-based counting is used in Swift. Replacing $n with #n helps on improving consistency of syntax in a small way (a focus of Swift 3), by removing this incoherence.

···

On 30 May 2016, at 23:17, Erica Sadun <erica@ericasadun.com> wrote:

On May 30, 2016, at 2:19 PM, Frédéric Blondiau via swift-evolution <swift-evolution@swift.org> wrote:

I personally never found that this “$n” convention was “Swift-like”... but it’s true that a “$n” is easier to spot than a “.n”, and I got used to also.

However, I realised how much this was disturbing for newcomers, when explaining closure shorthand argument names to a classroom of computer science students (aged 21) discovering Swift.

The feedback some gave me, during the course, was quite surprisingly strong and negative about this “$n” convention. This convinced me to write this proposal : for newcomers, the “$n” zero-based is something wrong.

I understand that association between tuples and function parameters in Swift is to be removed, but, in this case, as we have no parameters at all, I thought this was a distinct enough situation.

As suggested, considering this is a kind of compiler magic, using #0, #1 instead, may indeed be a better alternative.

I’m still waiting some feedback before writing an official proposal.

I really don't see a pressing need to change this. Zero-based counting is used in Swift arrays. I don't think the $-prefix is either superior or inferior to alternatives such as # or %, and has precedent in unix shell programming. Swift closures allow you to easily introduce meaningful names by using a closure signature with a parameter clause.

-- E

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

------------- End Message -------------

From James F


(Hooman Mehr) #2

I prefer keeping $ as a valid character for identifiers. Moreover, such a change will break a lot of client code other than closures (where it can be auto-migrated).

···

On May 31, 2016, at 2:51 AM, James F via swift-evolution <swift-evolution@swift.org> wrote:

Moreover, this would free up $ as an operator. I'm for removing it.