<div dir="ltr"><div>To the topic at hand, the project I’m currently working on has 2 enums, both with String raw values. For comparison, it has 3 classes (a Formatter subclass, the app delegate, and one more), 4 protocols, and 47 structs.</div><div><br></div><div>One of the enums exists to select among the handful of struct types which conform to one of the protocols.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">There are several things we have thought of that could potentially improve the situation, most notably exposing each case as an optional property.</blockquote><div><br></div><div>That would be very nice.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'd also really like to see switch-expressions (as opposed to statements).</blockquote><div><br></div><div>Hmm, would a syntax like this be appropriate?</div><div><br></div><div>switch someValue -> [String] {</div><div> case .helloWorld: return ["Hello", "world"]</div><div> default: return []</div><div>}</div><div><br></div><div>That way the existing switch statement could remain as-is, and the familiar function syntax would be used to specify the return type for switch expressions. The “return” keyword could even be elided for single-line cases as well, much like closures.</div><div><br></div><div>…oh, I just realized we’re on -users not -evolution here. Perhaps I’ll bring this up next time switch expressions are proposed.</div><div><br></div><div>Nevin</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 6, 2016 at 4:31 PM, Dave Abrahams via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><br>
on Sun Nov 06 2016, Tino Heth <swift-users-AT-swift.org> wrote:<br>
<br>
> Enums are a fundamental part of Swift, so I guess they won't change<br>
> much — but I wonder if anyone shares my observations in real-life use…<br>
><br>
> Afair, there are three different types of enums:<br>
> - Enums with raw values<br>
> - enums with associated objects<br>
> - Plain enums (no underlying value)<br>
><br>
> I use the first type quite often (as a convenient way to create string<br>
> constants, or for serialization), but see no real value in plain enums<br>
> (they offer nothing over enums backed with a raw value).<br>
><br>
> The second type is special:<br>
> It looks like a really cool concept, and and I started several designs<br>
> based on them — just to realize later that structs and classes are a<br>
> better fit.<br>
> My conclusion so far is that enums perform bad as soon as you want to<br>
> attach additional data or behavior; one or two computed properties are<br>
> ok, but those switch-statements quickly become a burden.<br>
> There are some options to work around this problem, but I guess I'll<br>
> just stay away from enums with associated objects by default (with the<br>
> exception of error-types — imho those can be modeled quite nicely).<br>
><br>
> So, that's my current perception, and I'm curious if others had<br>
> similar experiences — or, even more interesting, completely different<br>
> observations and elegant solutions based on enums.<br>
<br>
</span>I have personally always found that exuberant use of that kind of enum<br>
results in ergonomics and readability difficulties. There are several<br>
things we have thought of that could potentially improve the situation,<br>
most notably exposing each case as an optional property. I'd also<br>
really like to see switch-expressions (as opposed to statements). I'm<br>
not sure if that's really all we need in order to allow enums to reach<br>
their potential, though.<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
--<br>
-Dave<br>
</font></span><div class="gmail-HOEnZb"><div class="gmail-h5"><br>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
</div></div></blockquote></div><br></div></div>