[swift-evolution] [Proposal] Shorthand Argument Renaming

James F 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 ------------ 
Group: gmane.comp.lang.swift.evolution 
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
https://lists.swift.org/mailman/listinfo/swift-evolution
ëb

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



From James F


More information about the swift-evolution mailing list