[swift-evolution] named parameters - why hidden first?/proposal interest
Charles Srstka
cocoadev at charlessoft.com
Sun Jan 24 19:46:12 CST 2016
> On Jan 23, 2016, at 5:34 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>
> on Fri Jan 22 2016, Charles Srstka <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>
>>> On Jan 21, 2016, at 1:25 PM, Tony Parker via swift-evolution
>>> <swift-evolution at swift.org> wrote:
>>>
>>> We surveyed the entire surface area of the iOS and OS X SDKs,
>>> looking to see how many arguments typical methods had. We found that
>>
>>> the vast majority of methods actually have just one argument. If we
>>> went with a rule that first arguments should be named, then methods
>>> like:
>>>
>>> sayMessage(“hello”)
>>>
>>> would be this instead:
>>>
>>> say(message: “hello”)
>>>
>>> which isn’t really much of an improvement, in my mind.
>>
>> How about making it so that methods with just one argument have no
>> label on the argument by default, but methods with two or more
>> arguments have labels on all arguments? This would prevent what you
>> describe above, while eliminating the ugliness of one parameter being
>> treated differently from all the rest in the same method.
>
> ...and replace it with the ugliness of one parameter being treated
> differently from two. It would also force me to write "_" explicitly on
> the first parameter of all of my 2+ parameter methods. Yes, it's a
> little bit weird, but when optimizing APIs for readability at the call
> site, the defaults we have actually work in practice.
I’m playing devil’s advocate a bit, here—but is being forced to write “_” on a parameter any more onerous than being forced to write the entire label name out twice?
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160124/2bf8dd6a/attachment.html>
More information about the swift-evolution
mailing list