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

Jordan Rose jordan_rose at apple.com
Fri Mar 11 18:02:45 CST 2016


> On Mar 11, 2016, at 16:01 , Dave Abrahams <dabrahams at apple.com> wrote:
> 
> 
>> On Mar 11, 2016, at 2:57 PM, Jordan Rose <jordan_rose at apple.com <mailto:jordan_rose at apple.com>> wrote:
>> 
>> 
>>> On Mar 11, 2016, at 13:30 , Dave Abrahams <dabrahams at apple.com <mailto:dabrahams at apple.com>> wrote:
>>> 
>>> 
>>>> On Mar 11, 2016, at 11:27 AM, Joe Groff <jgroff at apple.com <mailto:jgroff at apple.com>> wrote:
>>>> 
>>>>> 
>>>>> On Mar 11, 2016, at 11:20 AM, Jordan Rose via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>> 
>>>>> 
>>>>>> On Mar 10, 2016, at 15:34 , Dave Abrahams via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>>> 
>>>>>> on Wed Mar 09 2016, Jordan Rose <swift-evolution at swift.org <mailto: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.
>>>>> 
>>>>> If it's easy to get these numbers, how many of the first parameters have the same label as the parameter name?
>>>> 
>>>> If you're going to measure that, you should also measure it for second, third, ..., Nth parameters too for comparison.
>>> 
>>> Anyone who wants to measure is free to do so: simple regexps and wc generally work for this purpose.
>>> 
>>> https://github.com/apple/swift-3-api-guidelines-review/tree/swift-3/Platforms <https://github.com/apple/swift-3-api-guidelines-review/tree/swift-3/Platforms>
>> …in retrospect, probably more of the Cocoa names would match up if they had this shorthand before:
>> 
>>   func beginSheetModal(for window: NSWindow, modalDelegate delegate: AnyObject?, didEnd didEndSelector: Selector, contextInfo contextInfo: UnsafeMutablePointer<Void>)
>> 
>> - for/window is a true difference
>> - modalDelegate/delegate is just convenience inside the method; it could have easily been modalDelegate/modalDelegate
>> - didEnd/didEndSelector actually does match up in the original; the importer has (correctly) changed it to not match
>> - contextInfo/contextInfo is a match
> 
> Sorry, I don’t know what you are trying to assert here.  Which shorthand?  We haven’t introduced any, and nobody’s proposing to add one.

The "shorthand" of providing a single name that is used both as an argument label and a parameter name. (Sorry for being unclear about that.) Objective-C has no way to do that, and so there's no incentive to make selector pieces exactly match parameter names.

Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160311/25a66207/attachment.html>


More information about the swift-evolution mailing list