<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I think I'm -1 on this. It makes things easier for the implementer of the function and harder for the caller. </div><div><br></div><div>It's not clear whether the caller could store an argument to pass in a variable, but if they could they would need to list out all cases in the type of the variable (unless these anonymous enums have structural subtyping). This is fragile. Any time that list changes all variable declarations will have to be updated.</div><div><br></div><div>Functions are implemented once and usually called more many times. It's better for callers if you just write it like this:</div><div><br></div><div>enum FitOrFill { case fit, fill }</div><div><div dir="ltr"><div class="gmail_quote"><div style="word-wrap: break-word;"><table style="border-spacing: 0px; border-collapse: collapse; color: rgb(51, 51, 51); font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 13px;"><tbody><tr><td style="padding: 0px 10px; vertical-align: top; overflow: visible; word-wrap: normal;"><font color="#000000" face="UICTFontTextStyleTallBody" size="3"><span style="background-color: rgba(255, 255, 255, 0);">func scaleAndCropImage(</span></font></td></tr><tr><td style="padding: 0px 10px; width: 50px; min-width: 50px; line-height: 18px; text-align: right; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding: 0px 10px; vertical-align: top; overflow: visible; word-wrap: normal;"><font color="#000000" face="UICTFontTextStyleTallBody" size="3"><span style="background-color: rgba(255, 255, 255, 0);"> image: UIImage,</span></font></td></tr><tr><td style="padding: 0px 10px; width: 50px; min-width: 50px; line-height: 18px; text-align: right; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding: 0px 10px; vertical-align: top; overflow: visible; word-wrap: normal;"><font color="#000000" face="UICTFontTextStyleTallBody" size="3"><span style="background-color: rgba(255, 255, 255, 0);"> toSize size: CGSize,</span></font></td></tr><tr><td style="padding: 0px 10px; width: 50px; min-width: 50px; line-height: 18px; text-align: right; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding: 0px 10px; vertical-align: top; overflow: visible; word-wrap: normal;"><font color="#000000" face="UICTFontTextStyleTallBody" size="3"><span style="background-color: rgba(255, 255, 255, 0);"> <b>operation: FitOrFill = .fit</b></span></font></td></tr><tr><td style="padding: 0px 10px; width: 50px; min-width: 50px; line-height: 18px; text-align: right; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding: 0px 10px; vertical-align: top; overflow: visible; word-wrap: normal;"><font color="#000000" face="UICTFontTextStyleTallBody" size="3"><span style="background-color: rgba(255, 255, 255, 0);"> ) -> UIImage {</span></font></td></tr></tbody></table></div></div></div><br><div>So unless these anonymous enums are structurally subtyped I think it's a bad idea. And introducing structural subtyping here seems like a pretty large hammer for this use case.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Sent from my iPad</div></div><div><br>On May 31, 2016, at 12:44 PM, Tony Allevato via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Big +1. I had similar thoughts a while back when I was writing some C++ or Java code that had boolean arguments, and I found myself hating how non-documenting they were and I would contrive two-valued enums to make call sites look better. Having a crisp clean syntax for this would be fantastic and encourage people to write self-documenting APIs.<div><br></div><div>Having argument labels solves some of the problems that come along with boolean arguments, but "fitImage" is a great example where the false case ("not fit?") doesn't really convey enough information (or can convey misleading information).</div><div><br><br><div class="gmail_quote"><div dir="ltr">On Tue, May 31, 2016 at 9:17 AM Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Here's a function signature from some code from today:<div><br></div><div><table style="border-spacing:0px;border-collapse:collapse;color:rgb(51,51,51);font-family:Helvetica,arial,nimbussansl,liberationsans,freesans,clean,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:13px"><tbody><tr><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"><span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">scaleAndCropImage</span>(</td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> image: UIImage,</td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> <span style="color:rgb(121,93,163)">toSize</span> <span>size</span>: CGSize,</td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> <b>fitImage: <span style="color:rgb(0,134,179)">Bool</span> <span style="color:rgb(167,29,93)">=</span> <span style="color:rgb(0,134,179)">true</span></b></td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> ) <span style="color:rgb(167,29,93)">-></span> UIImage {</td></tr></tbody></table><div><br></div><div><br></div><div>And here's what I want the function signature to actually look like:</div></div><div><br></div><div><table style="border-spacing:0px;border-collapse:collapse;color:rgb(51,51,51);font-family:Helvetica,arial,nimbussansl,liberationsans,freesans,clean,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:13px"><tbody><tr><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"><span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">scaleAndCropImage</span>(</td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> image: UIImage,</td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> <span style="color:rgb(121,93,163)">toSize</span> <span>size</span>: CGSize,</td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> <b>operation: <font color="#0086b3">(.Fit | .Fill)</font> <span style="color:rgb(167,29,93)">=</span> .<font color="#0086b3">Fit</font></b></td></tr><tr><td style="text-align: start; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); white-space: nowrap; vertical-align: top; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td><td style="padding:0px 10px;vertical-align:top;overflow:visible;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;word-wrap:normal;white-space:pre-wrap"> ) <span style="color:rgb(167,29,93)">-></span> UIImage {</td></tr></tbody></table><div><br></div></div><div><br></div><div>where I don't have to establish a separate enumeration to include ad-hoc enumeration-like semantics for the call. A while back, Yong hee Lee introduced anonymous enumerations (and the possibility of anonymous option flags) but the discussion rather died.</div><div><br></div><div>I'm bringing it up again to see whether there is any general interest in pursuing this further as I think the second example is more readable, appropriate, and Swifty than the first, provides better semantics, and is more self documenting.</div><div><br></div><div>Thanks for your feedback,</div><div><br></div><div>-- Erica</div><div><br></div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>