[swift-evolution] [Proposal] Shorthand Argument Renaming
conductator at ntlworld.com
Tue May 31 04:51:38 CDT 2016
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 ------------
MsgID: <D63CF3BB-A278-4428-82CA-6D47AA02426A at 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 at ericasadun.com> wrote:
>> On May 30, 2016, at 2:19 PM, FrĂ©dĂ©ric Blondiau via swift-evolution <swift-evolution at 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 at swift.org
------------- End Message -------------
From James F
More information about the swift-evolution