[swift-server-dev] Convert HTTPVersion to struct

Alex Blewitt alblue at apple.com
Wed Jun 14 04:37:56 CDT 2017


> On 14 Jun 2017, at 07:41, Rien via swift-server-dev <swift-server-dev at swift.org> wrote:
> 
> The choices seem to be:
> 
> 1) String
> 2) Enum
> 3) Tuple
> 4) Struct
> 5) Class
> 
> To me that leaves option 2 and 4.
> Advantage of 2 over 4:
> 
> - I find the abstraction a better match. The difference between 1, 1.1 and 2 is such that it makes little sense to be to differentiate based on the numerical values. It makes much more sense to differentiate based on the “whole number”. AFAIIC they could just as easily have named the versions A, B, C etc. The numbers do not convey any information as such.
> - Switch is easier and more intuitive to use.
> - Enums can have additional properties and operations similar to struct.
> 
> Advantage of 4 over 2:
> I don’t see any.


The problem with using any fixed-sized, closed set enum is that you are not going to capture every possible status code in the implementation. Sure, you might capture them as they exist /now/ but they may be added to in the future. In addition, you can't really group them into ranges (e.g. 1xx, 2xx, 3xx, 4xx, 5xx) which have definite meanings even if the actual status code is not known at the time the program was written.

Having worked with HTTP libraries in the early days of Java, and seeing the HTTP/1.0 -> HTTP/1.1 and then subsequent RFCs adding further codes (e.g. https://tools.ietf.org/html/rfc6585 <https://tools.ietf.org/html/rfc6585>) expecting the set of codes to be a closed set doesn't work. You might be able to get away with an enum-of-five (corresponding to the 1xx, 2xx, 3xx, 4xx, 5xx) but that doesn't add much and you'd still need to have the numerical values stored anyway.

Alex

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170614/81f89616/attachment.html>


More information about the swift-server-dev mailing list