<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">With everything quiet on this discussion since my last update removing defaults, I've gone ahead and submitted a pull request (<a href="https://github.com/apple/swift-evolution/pull/585" class="">https://github.com/apple/swift-evolution/pull/585</a>) with the latest draft. I'm certainly happy to still update it if anything arises.<div class=""><br class=""></div><div class="">Thanks to all who helped out!</div><div class=""><br class=""></div><div class="">—Tim<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 13, 2017, at 12:23 AM, Rien <<a href="mailto:Rien@Balancingrock.nl" class="">Rien@Balancingrock.nl</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">+1<br class=""><br class="">Site: <a href="http://balancingrock.nl" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Swiftrien" class="">http://github.com/Swiftrien</a><br class="">Project: <a href="http://swiftfire.nl" class="">http://swiftfire.nl</a><br class=""><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 13 Jan 2017, at 03:01, Tim Shadel via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">Fantastic points, all. Let me reply to a few.<br class=""><br class="">First, the odd situations you mentioned with the defaults were spot on. I had seen them, and thought a bit about it, but having you write it out in code made it obvious that they're pretty harmful. I've removed defaults entirely (see the updated Alternatives and Errors sections). This is actually a really good indicator of whether you should use this syntax or not. If you'll save a noticeable amount of space by using a default, then this isn't the syntax for your situation.<br class=""><br class="">To make that more obvious, I've added a Mixed Use Example (<a href="https://gist.github.com/timshadel/5a5a8e085a6fd591483a933e603c2562#mixed-use-example" class="">https://gist.github.com/timshadel/5a5a8e085a6fd591483a933e603c2562#mixed-use-example</a>) showing how simple it is to use the existing syntax when you have a default and a small number of exceptions, alongside the case block syntax for things that are unique for each case. So, to summarize, I think that forcing the additional code for each case is a good thing so that this syntax remains the exception used when needed, instead of becoming the rule.<br class=""><br class="">Now to your other points. The intent isn't to alter the amount of code required to accomplish the task (code *complexity*), but to simplify *maintenance and understanding* by allowing you to organize the code either by property or by case (according to the merits of the code and your judgement). Indeed, I try to highlight in the proposal that this usually _increases_ code verbosity slightly in favor of the readability gained by shifting the code layout.<br class=""><br class="">Finally, to your point about attaching properties to values (also echoed in David's musings about tagged unions vs Swift enums), it is different, but I'm not sure of a cleaner way to group all the code related to a single case for complex enums. In another light, no other type in Swift makes such heavy use of `switch` statements as a mechanism to organize code, and so this starts to make enum code look more like the rest of the code you find in Swift projects, which could be a good thing for long-term readability.<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Jan 11, 2017, at 9:22 AM, Tony Allevato <<a href="mailto:tony.allevato@gmail.com" class="">tony.allevato@gmail.com</a>> wrote:<br class=""><br class="">I'll summarize my thoughts for now, after thinking about it for a bit longer:<br class=""><br class="">Plusses:<br class="">+ In some cases it's nicer to have the ability to group functionality at each case rather than spread across methods lower in the type definition. I've written enums that were like state machines where being able to have the next state transition and other associated data grouped with the case would have made the code a bit cleaner, IMO.<br class="">+ This is the cleanest syntax I've seen proposed for this idea.<br class=""><br class="">Things that worry me:<br class="">– It's a new way to express the same idea without necessarily *simplifying* it in terms of code complexity.<br class="">– It adds a fair amount of complexity to the compiler, to build the implicit self-switch and merge the implementations for each partial property/function.<br class="">– It would be the first time, I believe, in Swift where properties/method implementations are attached to *values* rather than just to the *type*. That's quite a departure from the way we model these concepts.<br class="">– The use of the type-defined implementation as the default when a case-defined implementation is omitted can lead to some bizarre combinations, which I think need to be addressed in the proposal. Consider this:<br class=""><br class="">```<br class="">enum Foo {<br class=""> var description: String {<br class=""> switch self {<br class=""> case .bar: return "bar"<br class=""> case .baz: return "baz"<br class=""> default: return ""<br class=""> }<br class=""><br class=""> case bar<br class=""> case baz<br class=""> case quux {<br class=""> var description: String { return "quux" }<br class=""> }<br class="">}<br class="">```<br class=""><br class="">Should the user be able to omit the `default` case because everything is exhaustively covered without it? *Conceptually* yes, but that would require the compiler to analyze the switch statement inside `description` and understand that, which is probably not feasible for anything but the simplest examples (and perhaps not even for those). Otherwise, it would presumably transform the implementation to this:<br class=""><br class="">```<br class=""> var description: String {<br class=""> switch self {<br class=""> case .quux: return "quux"<br class=""> default:<br class=""> switch self {<br class=""> case .bar: return "bar"<br class=""> case .baz: return "baz"<br class=""> default: return ""<br class=""> }<br class=""> }<br class="">```<br class=""><br class="">...which produces the expected output, but the generated code might not be ideal.<br class=""><br class="">That makes me question whether we should allow default implementations at all. If we didn't allow it, we potentially require the user to write *more* code because they would have to duplicate the defaults under each case separately. But it opens a door to potential confusion if we do allow them.<br class=""><br class="">So... I guess I'm on the fence right now. I want to support this from the point of view that syntactically it would improve the quality of some of the enums I've written, but I'm hedging a bit conservatively because of those concerns above.<br class=""><br class=""><br class="">On Wed, Jan 11, 2017 at 7:08 AM David Sweeris <<a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a>> wrote:<br class=""><br class="">On Jan 11, 2017, at 08:48, Derrick Ho via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">Interesting proposal Tim. So instead of repeating the enum cases multiple times we repeat the functions multiple times?<br class=""><br class="">I feel like this merely flipping the complexity but not really getting rid of it.<br class=""></blockquote><br class="">I think you have correctly summarized the proposal.<br class=""><br class="">The complexity can't be gotten rid of (except maybe with macros... depending on the details, of course). Sometimes viewing the same thing from a different angle can be helpful. As long as this syntax is "in addition to" and not "instead of", the only downside I can see to allowing this is a bit of "language bloat", which doesn't particularly bother me. I don't know how hard it would be for the compiler to sort out which "mode" it should parse the enum in, though, especially since you might want to write some parts in the regular way and some parts in this new way.<br class=""><br class="">So... I guess I'm +1, pending someone who knows more about compiler internals weighing in on implementation implications.<br class=""><br class="">- Dave Sweeris<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>