<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="">Hi Paul, </div><div class=""><br class=""></div>Your example, can’t use type inference to determine the type of str which feels clumsy, and “str =“ is duplicated over and over. You also have no guarantee that str get assigned in each case. While this example that error is not likely, if your cases are more complex that could become a problem. Also, if I am writing something that is functional, it is less likely, as Charles points out, another developer will stick some side effect based code in your cases. Finally, for the proposal you could write it even more compactly: Switch statements seem much more heavyweight. <div class=""><br class=""></div><div class=""><span class="" style="font-size: 11px; font-family: Menlo; color: rgb(167, 29, 93); white-space: pre-wrap;">let</span><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; color: rgb(50, 51, 51);"> str = match(state)</span><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; color: rgb(50, 51, 51);"> {</span><span class=""> </span><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; color: rgb(167, 29, 93);">cases</span><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; background-color: rgb(247, 247, 247);"><font color="#323333" class=""> </font></span><font color="#0056d6" class=""><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap;">.</span><span style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">Cold</span></font><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">:</span><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); background-color: rgb(247, 247, 247); white-space: pre;" class=""> </span><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">“Too cold”</span><span style="background-color: rgb(247, 247, 247);" class="">, </span><font color="#0056d6" class=""><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap;">.</span><span style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">Hot:</span></font><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); white-space: pre-wrap; background-color: rgb(247, 247, 247);" class=""> </span><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">“Too hot”</span></div><div class=""><span class="" style="font-size: 11px; font-family: Menlo; white-space: pre-wrap; color: rgb(167, 29, 93);"><span class="" style="white-space: pre;">        <span class="Apple-tab-span">                </span></span>default</span><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); background-color: rgb(247, 247, 247);" class=""><span style="white-space: pre-wrap;" class="">: </span></span><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); background-color: rgb(247, 247, 247);" class="">“Just right” </span><span style="color: rgb(50, 51, 51); font-family: Menlo; font-size: 11px; white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">}</span></div><div class=""><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); white-space: pre-wrap; background-color: rgb(247, 247, 247);" class=""><br class=""></span></div><div class=""><span style="font-size: 11px; font-family: Menlo; color: rgb(50, 51, 51); white-space: pre-wrap; background-color: rgb(247, 247, 247);" class="">Cheers,</span></div><div class="">- Paul</div><div class=""><br class=""><div><blockquote type="cite" class=""></blockquote></div></div><div><blockquote type="cite" class=""><div class="">On Jan 28, 2016, at 11:37 PM, Charles Constant via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">@Paul<div class=""><br class=""></div><div class="">On the more objective side of things, there is also the fact that, as the proposal states, it's nice to have protection against this happening:</div><div class=""><br class=""></div><div class=""><div style="font-family:Menlo;font-size:10.5px;margin:0px;line-height:normal" class=""> <span style="color:rgb(50,62,125)" class="">let</span> str: <span style="color:rgb(88,126,168)" class="">String</span></div><div style="font-family:Menlo;font-size:10.5px;margin:0px;line-height:normal" class=""> <span style="color:rgb(50,62,125)" class="">switch</span>(<span style="color:rgb(88,126,168)" class="">state</span>) {</div><span class="im" style="font-family:Menlo;font-size:11px"><div style="margin:0px;font-size:10.5px;line-height:normal" class=""> <span style="color:rgb(50,62,125)" class="">case</span> .Cold: <span style="color:rgb(88,126,168)" class="">str</span> = <span style="color:rgb(132,62,100)" class="">"Too cold"; </span><span style="color:rgb(50,62,125)" class="">self</span><span style="color:rgb(34,34,34)" class="">.</span>freezer<span style="color:rgb(34,34,34)" class="">.</span><span style="font-size:10.5px;color:rgb(50,62,125)" class="">stop</span><span style="color:rgb(34,34,34)" class="">()</span></div><div style="margin:0px;font-size:10.5px;line-height:normal" class=""> <span style="color:rgb(50,62,125)" class="">case</span> .Hot: <span style="color:rgb(88,126,168)" class="">str</span> = <span style="color:rgb(132,62,100)" class="">"Too hot"</span></div><div style="margin:0px;font-size:10.5px;line-height:normal" class=""> <span style="color:rgb(50,62,125)" class="">default</span>: <span style="color:rgb(88,126,168)" class="">str</span> = <span style="color:rgb(132,62,100)" class="">"Just right"</span></div><div style="margin:0px;font-size:10.5px;line-height:normal" class=""> }</div></span></div><div class=""><br class=""></div></div></div>
_______________________________________________<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=""></div></blockquote></div><br class=""></body></html>