[swift-evolution] [Review] SE-0023 API Design Guidelines

Radosław Pietruszewski radexpl at gmail.com
Mon Jan 25 11:01:49 CST 2016


Paul, let’s start a new thread about this — I was going to write about the same idiom, but it’s out of scope of this review.

I disagree with Dave that this is just a EDSL, I think things like completion/success/failure handlers are a very common pattern, and it would be great to have consistent naming and a Guidelines recommendation for them. (Usually in the context of argument names, not chainable methods, which are, indeed, quite DSL-y).

— Radek

> On 25 Jan 2016, at 04:48, Paul Cantrell via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> Siesta uses the widespread fluent style of attaching callbacks to a request:
> 
>     resource.load()
>         .onCompletion { _ in stopSpinnyThing() }
>         .onSuccess { _ in showHappyFace() }
>         .onFailure { _ in showSadFace() }
>         .onNewData { _ in soundTrumpets() }
> 
> These methods mutate the receiving request (by adding a callback), and the guidelines thus say that they should be named as imperative verbs. The results of that don’t seem like an improvement:
> 
>     resource.load()
>         .addCompletionCallback { _ in stopSpinnyThing() }
>         .addSuccessCallback { _ in showHappyFace() }
>         .addFailureCallback { _ in showSadFace() }
>         .addNewDataCallback { _ in soundTrumpets() }
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160125/8d724d9b/attachment-0001.html>


More information about the swift-evolution mailing list