<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=""><div class="">Here is a correction to the equivalent declaration. It would be a RawRepresentable String enum to be compatible with serialization mechanisms e.g. JSON. and other representations. Again, the name could be auto-generated to keep the syntax succinct.</div><div class=""><br class=""></div><div class="">…</div><div class=""><br class=""></div><div class="">would be equivalent to</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(185, 45, 93);">class</span><span class="">&nbsp;</span><span style="color: rgb(135, 78, 254);" class="">MyImage</span><span class="">&nbsp;&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);"><span class="" style="color: rgb(0, 0, 0);">&nbsp;<span class="Apple-tab-span" style="white-space: pre;">        </span></span><span class="" style="color: rgb(185, 45, 93);">enum</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span>ScaleCropFitFill<span class="" style="color: rgb(0, 0, 0);">&nbsp;:&nbsp;<span style="color: rgb(135, 78, 254);" class="">String&nbsp;</span>{</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="Apple-tab-span" style="white-space: pre;">                </span>case &nbsp;<span class="" style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);"><b class="">Fit</b></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="Apple-tab-span" style="white-space: pre;">                </span>case &nbsp;<span class="" style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);"><b class="">Fill</b></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}&nbsp;</div></div><div class="">...</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On May 31, 2016, at 12:25 PM, Christopher Kornher &lt;<a href="mailto:ckornher@me.com" class="">ckornher@me.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Apologies for using you as a relay...<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">Re: [swift-evolution] Ad hoc enums / options</b><br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">May 31, 2016 at 11:43:43 AM MDT<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Charles Constant &lt;<a href="mailto:charles@charlesism.com" class="">charles@charlesism.com</a>&gt;<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Cc: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Swift Evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;, Christopher Kornher &lt;<a href="mailto:ckornher@me.com" class="">ckornher@me.com</a>&gt;<br class=""></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Reply-To: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Charlie Monroe &lt;<a href="mailto:charlie@charliemonroe.net" class="">charlie@charliemonroe.net</a>&gt;<br class=""></span></div><br class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I have mixed feelings about this since it may lead to redeclarations over and over of the same values instead of actually declaring an enum.</span></div></blockquote></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class="">I have two suggested “improvements”</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">1) Make the enum String raw-representable. Name it somehow. This does not affect Erica’s original syntax.</div><div style="margin: 0px; line-height: normal;" class="">2) Force an explicit name.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">#2 &nbsp;does add to the length of function declarations, so it is a tradeoff. Perhaps the name could be optional, but...</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">#2 would improve debug representations of the value by providing a name that can be found in source code</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">In a full-featured metadata system, it would probably be nice to have a type for the enum to simply the handling of all enums.&nbsp;</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">#2 is more future-proof. Systems get more complex over time and one use of a type becomes many.&nbsp;</div><div style="margin: 0px; line-height: normal;" class="">The enum type name (auto-generated or required, it makes no difference) would be scoped to the function’s namespace e.g. (fixing the typo) :</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="color: #b92d5d" class="">class</span><span style="" class="">&nbsp;</span>MyImage<span style="" class=""> &nbsp;{</span></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #b92d5d" class="">func</span><span style="" class=""> </span>scaleAndCropImage<span style="" class="">(</span></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">                </span>image: UIImage,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>toSize size: CGSize,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>operation:&nbsp;<span style="color: rgb(135, 78, 254);" class="">ScaleCropFitFill</span>{ .<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span> | <span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fill</b></span>} = .<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span class="Apple-tab-span" style="white-space:pre">        </span>) -&gt; UIImage {…}</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">would be equivalent to:</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="color: #b92d5d" class="">class</span><span style="" class="">&nbsp;</span>MyImage<span style="" class=""> &nbsp;{</span></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="" class="">&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #b92d5d" class="">enum</span><span style="" class=""> &nbsp;</span>ScaleCropFitFill<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case &nbsp;<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case &nbsp;<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fill</b></span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}&nbsp;</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(135, 78, 254);" class=""><span style="" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="color: #b92d5d" class="">func</span><span style="" class=""> </span>scaleAndCropImage<span style="" class="">(</span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>image: UIImage,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>toSize size: CGSize,</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>operation: <span style="color: #874efe" class="">ScaleCropFitFill</span> = .<span style="line-height: normal; font-family: Menlo; -webkit-font-kerning: none; color: rgb(0, 134, 179);" class=""><b class="">Fit</b></span></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>) -&gt; UIImage {…}</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">There are two ways that an implementation could evolve from having one use of the enum in a call to multiple uses;</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">1) The function is refactored into more functions internal to the original function’s namespace: module/class/struct/enum.</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this case, it would be appropriate to leave the enum declaration in function declaration to indicate that this is the only public use of the enum.</div><div style="margin: 0px; line-height: normal;" class="">2) More public functions are created that use the enum</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>In this case, it would be appropriate to declare the enum within the same scope. Existing code would not be affected. Smart editors could provide this refactoring.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">- Chris K</div></div></div></div></blockquote></div><br class=""></body></html>