[swift-evolution] [Pitch] Make the first parameter in a function declaration follow the same rules as the others

Dave Abrahams dabrahams at apple.com
Thu Mar 10 17:34:49 CST 2016


on Wed Mar 09 2016, Jordan Rose <swift-evolution at swift.org> wrote:

> This is my concern too. Our guidelines often lead to the first
> parameter having a label, but usually that name isn't the same as the
> name of the parameter—one's a preposition, the other's a noun. I'm
> pretty sure the common case is still unlabeled. 

It's about 50/50 (slight edge to labeled first parameters) in the
imported Cocoa APIs.

> Does that justify the complexity of the current rule?
>
> (But because Objective-C methods will now often have labeled
> arguments, it would at least no longer be a marker differentiating
> "pure Swift" code from "Cocoa" code.)
>
> Jordan
>
>> On Mar 9, 2016, at 14:32, Radosław Pietruszewski via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>> Looking at my code, the majority of methods should still have the first parameter unlabeled. 
>> 
>> I like the consistency of what you’re proposing and the fact that I
>> don’t have to write `func foo(someArgument someArgument: T)`
>> anymore. But I also fear people won’t get it that they can (and in
>> many, probably most, situations should) make the first parameter `_
>> foo`.
>> 
>> — Radek
>> 
>>> On 09 Mar 2016, at 19:58, Joe Groff via swift-evolution
>>> <swift-evolution at swift.org
>>> <mailto:swift-evolution at swift.org>>
>>> wrote:
>>> 
>>> Our accepted naming guidelines have embraced first argument labels
>>> for functions and methods. This weakens our justification for
>>> making the first parameter declaration in a `func` declaration
>>> behave differently from the others, implicitly being unlabeled. It
>>> seems pretty clear to me we should make all of the parameter
>>> declarations behave uniformly:
>>> 
>>> func foo(x: Int, y: Int) // Should declare foo(x:y:), instead of foo(_:y:)
>>> func foo(_ x: Int, y: Int) // Explicitly declares foo(_:y:)
>>> 
>>> This would also make `init` and `func` parameters behave
>>> consistently, which is nice. There may still be hope for our
>>> keyword argument rules to one day be shorter than the Smalltalk
>>> spec…
>>> 
>>> -Joe
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
-Dave



More information about the swift-evolution mailing list