[swift-evolution] Opt-out for first unnamed parameter instead of opt-in

Brent Royal-Gordon brent at architechies.com
Mon Feb 8 16:17:53 CST 2016


> Why we can not stay with the first one that is more consistent? The impact is to replace declarations like:
> 
> 
> func myMethod(something something: AnyObject)
> 
> With
> 
> func myMethod(something: AnyObject)
> 
> 
> And replace:
> 
> func myOtherMethod(something: AnyObject)
> 
> With
> 
> func myOtherMethod(_ somethings: AnyObject)

An alternative might be to always require both names, but offer a shorthand for saying they're the same. Purely as an illustrative example, this would mess up syntax highlighting, but it follows an English punctuation usage:

	func myMethod(something ": AnyObject) 	// shorthand for `something something:`

This is perhaps a little more realistic, drawing on our convention of magic compiler substitution:

	func myMethod(something #: AnyObject)	// shorthand for `something something:`

(Swift 1, of course, had `#something` for that, but dropped it, apparently because it was arbitrary and became rarely needed when methods and functions got the same parameter labeling rules in Swift 2. Neither of those would be the case now.)

In short, the whole "should we have default labels or not" question can simply go away forever for an extra two characters per parameter. That might be worth it.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list