[swift-evolution] [Proposal] Shorthand Argument Renaming

Frédéric Blondiau frederic.blondiau at douwere.com
Tue May 31 03:21:53 CDT 2016


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



More information about the swift-evolution mailing list