[swift-evolution] When to use argument labels, part DEUX

Dave Abrahams dabrahams at apple.com
Sat Feb 13 12:18:36 CST 2016


on Sat Feb 13 2016, Radosław Pietruszewski <swift-evolution at swift.org> wrote:

>>>>> but I want to make sure if I interpret the proposed guidelines right.
>>>>> 
>>>>> 	func actionForCommand(command: UIKeyCommand) -> String? {
>>>>> 
>>>>> This should become “actionFor(command: c)” — which isn’t an obvious
>
>>>> 
>>>> That looks like a call, in which case the API above doesn't allow an
>>>> argument label.
>>> 
>>> I’m sorry — I got confused — what do you mean here?
>> 
>> Sorry, I didn't notice that you both transitioned from declaring
>> (actionForCommand(_)) to calling (actionFor(command:)) *and* changed the
>> API at the same time.
>> 
>> So, I would say the guidelines say the call should look like:
>> 
>>    b.action(for: c)
>>> 
>>>> 
>>>>> It should be `createAttribute(tag: t, data: d)`. 
>>>> 
>>>> Again that looks like a call, so for the above declaration it would be
>>>> 
>>>>     createAttribute(t, d)
>>>> 
>>>>> Alternatively, it could be `attributeFor(tag: t, data: d)` — I could
>>>>> go either way.
>>>> 
>>>> Why “for?” Can you explain the semantics of this method (or show a BCDC)?
>>> 
>>> This is a initializer-like helper method that instantiates a
>>> SecKeychainAttribute from passed parameters.
>> 
>> If it's a factory, I think guidelines prescribe the call should look like:
>> 
>>   makeAttribute(tag: t, data: d)
>
> So that’s interesting, because there’s a difference in convention
> between a factory/initializer-like function:
>
> 	makeFoo(this:, that:)
>
> and a getter/finder-like function:
>
> 	foo(withThis:, that:)

Yes, that's the intention.  When the distinction makes no difference,
you should treat the function like a getter/finder, IIUC.

> I think that (in particular the difference in the treatment of
> argument labels) is the part that makes me most uncomfortable about
> the latest draft. Perhaps it isn’t such a big deal, since you usually
> don’t see the two next to each other, and as was noted, most
> finder-like functions only come with a single parameter, while
> initializers and factory methods very commonly have many parameters...

-- 
-Dave



More information about the swift-evolution mailing list