[swift-server-dev] Prototype of the discussed HTTP API Spec

Paulo Faria paulo at zewo.io
Fri May 26 18:19:51 CDT 2017


I'm not sure I follow your example. Cat.Animal doesn't make much sense to
me while Animal.Cat makes perfect sense.

import Animal

let pet = Cat()

When importing HTTP you know you'll deal with HTTP requests and not
anything else. And if you do import another module which also has Request
(never happened to me) you have to make it clear which one you're referring
to. So you'll have to do HTTP.Request, SOAP.Request. So in both scenarios,
there won't be any confusion. On the other hand prefixing everything ends
up adding noise to the API.

> Your particular setup is sync, right? ;->

It is, but I really don't care about prefixing with Sync, if needed. I
honestly find it weird to mark an API Sync since really, most of the APIs
are synchronous (in general of course). Is there any async API in Swift's
standard library? But again, non-issue for me. I'd be totally ok with Sync.

> For async you usually need some way to hold on to a buffer, and that is
DispatchData

Sorry can you elucidate that? If you have the pointer, you're holding the
buffer aren't you? I'm not sure I follow the issue.


On 26 May 2017 at 20:09, Helge Heß via swift-server-dev <
swift-server-dev at swift.org> wrote:

> On May 27, 2017, at 12:55 AM, Paulo Faria <paulo at zewo.io> wrote:
> > Helge! I agree with most of your suggestions and I'll update my proposal
> with them. There's only one I'm not with you and it's about the HTTP
> prefix. The example you mentioned could be easily solved by adding `HTTP.`
> when referring to the specific type.
> >
> > import HTTP
> > import SOAP
> >
> > let request = HTTP.Request()
> >
> > We have used Request and Response without prefixes for about two years
> and not once anyone complained about that. I imagine others who use the
> same naming scheme can testify to that.
>
> Having seen such overloading in Java frameworks before I simply disagree
> with that. The object in question is plainly a HTTPRequest(Head) not just
> some arbitrary request. The ‘HTTP’ really is part of the thing. In fact the
> ‘arbitrary’ request could be an NSOperation, providing functionalities such
> as pause, cancel, etc.
>
> In a way it is like
>
>   import Cat
>
>   let pet = Animal() // resolving to Cat.Animal()
>
> But well, if people really like that … ;-) I vote against it.
>
> > About Sync/Async prefix. I was talking about type prefixes not method
> prefixes. We definitely shouldn't prefix function APIs with sync or async.
> I honestly don't care too much about which one to use as a default. I just
> think it makes more sense to prefix the Async ones.
>
> Your particular setup is sync, right? ;->
>
> > About raw buffers we could provide APIs that take an array of
> Unsafe[Mutable]RawBufferPointer to pass them to readv, writev and
> company. Those could also be easily converted to DispatchData in the
> frameworks that prefer to use it.
>
> This is a little related to sync vs async. For async you usually need some
> way to hold on to a buffer, and that is DispatchData. For sync you usually
> don’t have to, and pointers to buffers can be faster.
>
> Though I do think that sync is more appropriate for many server builders,
> I think that the goal for Swift-Server would be more oriented towards
> async. I may be wrong.
>
> hh
>
>
> _______________________________________________
> swift-server-dev mailing list
> swift-server-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-server-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170526/2e8b7d43/attachment.html>


More information about the swift-server-dev mailing list