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

Charles Constant charles at charlesism.com
Tue Feb 2 15:08:30 CST 2016


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

I started doing that a couple months ago. It's a fine option, imho. I'd
prefer we keep func names as verbs only, I'm fine with a bunch of
overloaded funds (the arguments are enough). I prefer arguments with
prepositions, since without can be too vague. The last couple months I've
found naming things to be much easier, and understanding the functions
easier at a glance because each part of the name does the same thing every
time - unlike a verb sandwiched, sometimes with a noun, or argument labels
that "seem good at the time" but then are confusing for the reasons
Haaravik points out.

So for me, I prefer to read this type of thing:

func farfelize( to_foo foo:Obj!, using_bar bar:Obj!, with_options
opts:Choice! ){ ... }





On Wed, Jan 27, 2016 at 2:37 PM, Douglas Gregor via swift-evolution <
swift-evolution at swift.org> wrote:

>
> 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> 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
>
>
>
> _______________________________________________
> 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/20160202/b17501e4/attachment.html>


More information about the swift-evolution mailing list