<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
> Hello everyone!<br class="">> <br class="">> I was unable to make the kick-off meeting for the HTTP sub-team, but I looked over themeeting notes(<a href="https://docs.google.com/document/d/1SWK0qBDi-9DeLJwHlcXcPU7h22JU-DWW8HTVuHbTQiw/edit" class="">https://docs.google.com/document/d/1SWK0qBDi-9DeLJwHlcXcPU7h22JU-DWW8HTVuHbTQiw/edit</a>)and found some topics that I think could use some more on-the-record discussion.<br class="">> <br class="">> A few questions that I wanted to raise:<br class="">> <br class="">> 1. Do we want to use concrete types or protocols for Request/Response?<br class="">> 2. If we use concrete types, do we want value or reference semantics?<br class="">> 3. When is it more convenient to have reference semantics?<br class="">> 4. Are there problems that can't be solved with value semantics?<br class="">> <br class="">> I would like to avoid bike-shedding, and I think this can be done by providing real examples rather than just talking about the pros and cons.<br class="">> --<br class="">> Dan Appel<br class="">> <br class="">> <br class="">><span class="Apple-converted-space"> </span>
<div class=""><span class="Apple-converted-space"><br class=""></span></div><div class=""><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">My own responses:</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">>1. Do we want to use concrete types or protocols for Request/Response?</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">When working on <a href="https://github.com/open-swift" class=""><span style="color: rgb(228, 175, 9);" class="">Open Swift</span></a>, this was a hot topic since we believed that it would be unsafe to have a protocol that would allow both value and reference types. We arrived upon the `{Request|Response}Representable` pattern which worked but was a bit of a mess. Because of this, I would prefer concrete Request/Response types.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">>2. If we use concrete types, do we want value or reference semantics?</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">What I think makes this easier is that the "big four" have each taken a slightly different approach that can be used as a reference.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""><span style="text-decoration: underline ; color: #e4af09" class=""><a href="https://github.com/Zewo/Zewo/blob/master/Modules/HTTP/Sources/HTTP/Message/Request.swift#L3" class="">Zewo</a></span> - struct, value semantics</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""><span style="text-decoration: underline ; color: #e4af09" class=""><a href="https://github.com/vapor/engine/blob/master/Sources/HTTP/Models/Request/Request.swift#L4" class="">Vapor</a></span> - closed class, reference semantics</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""><span style="text-decoration: underline ; color: #e4af09" class=""><a href="https://github.com/IBM-Swift/Kitura/blob/master/Sources/Kitura/RouterRequest.swift#L26" class="">Kitura</a></span> - closed class + has-a pattern, reference semantics</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""><span style="text-decoration: underline ; color: #e4af09" class=""><a href="https://github.com/PerfectlySoft/Perfect-HTTP/blob/master/Sources/HTTPRequest.swift#L25" class="">Perfect</a></span> - class protocol, reference semantics</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">Zewo is the outlier here, but I would like to note as a contributor to Zewo that we have not ran into situations where value semantics create an impassable roadblock. </div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">To me, it makes sense to pass them around as values since they don't have any logic of their own. Requests/Responses can't send themselves, they can only read and modified. It also gives me as a user more safety to pass them around since I know that they won't be modified implicitly.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">Take the following pseudo-code as an example:</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">HTTPServer.onRequest { request in</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""> print(request.sourceIp)</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""> HTTPClient.send(request)</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""> print(request.sourceIp)</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">With reference semantics, there is no guarantee that sourceIp will be the same before and after sending off the request. After all, it <i class="">could</i> make sense for the HTTPClient to modify the sourceIp before sending off the request. This of course a contrived example, but the point stands.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">Anyway, I think it would be great if we could have people talk about their own experiences.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">>3. When is it more convenient to have reference semantics?</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">In the middleware chain architecture that we decided on in Zewo (the other ones have something similar), it can be convenient to modify requests in the responder and have that reflect in the middleware. I think this problem is best solved with `inout` parameters rather than reference types, but that is my personal opinion.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">>4. Are there problems that can't be solved with value semantics?</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">I haven't found one that we can't solve, but I'm sure others can bring something interesting to the table.</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class="">--</div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(69, 69, 69);" class="">Dan Appel</div></div></body></html>