[swift-evolution] [Review] SE-0005 Better Translation of Objective-C APIs Into Swift

Douglas Gregor dgregor at apple.com
Wed Jan 27 16:37:47 CST 2016


> On Jan 27, 2016, at 2:15 PM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On 27 Jan 2016, at 21:48, Rob Mayoff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>>> -  func respondWith(data: Data)
>>>> +  func respond(data data: Data)
>>> 
>>> This one is unusual. I don’t mind `respond(data: …)`, but generally there’s a word to the right of “with”, and here the “with” was just to imply the argument without naming it.
>> 
>> The original ObjC method name was “respondWithData:”. “Data” restates type info, so SE-0023 stripped it off; this transformation makes it the first argument label.
>> 
>> Can I tell, at a call site, whether `respond(data: someData)` is responding with someData, or responding to someData?
>> 
>> That is, can I tell whether someData is the response, or instead is something from the request that the receiver will use to compute the response?
>> 
>> If I see `respondWith(someData)` or `respondWith(data: someData)` or `respondWithData(someData)`, it's clear to me that someData is the response, while a hypothetical call `respondTo(someData)` would tell me that someData is the input to the response-computing algorithm.
> 
> I’d like to reiterate that my preference for cases like these would be:
> 
> 	respond(withData data: Data)
> 
> This way the action (function name) is still simplified to respond, but the sentence structure remains for clarity, which I still think is the best of both worlds.

Observation: I’ve never seen anyone write Swift code this way, with a proposition “with” on the first argument label. Have you?

	- Doug


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160127/49bca45d/attachment.html>


More information about the swift-evolution mailing list