[swift-evolution] named parameters - why hidden first?/proposal interest

Howard Lovatt howard.lovatt at gmail.com
Mon Jan 25 01:24:12 CST 2016


I think that the simple rule that all parameters, wether in init or a method have named parameters. I.E. I like:

    say(message: “hello”)

Since to me it is clear. 

I also note there is considerable discussion in the API guidelines about how to qualify method names particularly when type is vey general like Any, e.g. append:

    anyArray.append([1, 2, 3])

Does this append the single element [1, 2, 3] (an array) or does it append three separate elements, 1, 2, and 3? If the argument is labeled then it is clear:

    anyArray.append(element: [1, 2, 3]) // append with a single argument
    anyArray.append(elements: 1, 2, 3) // append with var arts

Sent from my iPad

> On 25 Jan 2016, at 12:46 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 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> 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
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160125/a7b027ee/attachment.html>


More information about the swift-evolution mailing list