[swift-evolution] When to use argument labels, part DEUX
Radosław Pietruszewski
radexpl at gmail.com
Sat Feb 13 04:59:39 CST 2016
>>>> 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:)
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...
Best,
— Radek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160213/87c76129/attachment.html>
More information about the swift-evolution
mailing list