<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=""><br class=""></div>That’s an interesting approach. &nbsp;My cases tend to be more localized (the let is right before the if), but I can see how the struct approach would be better if the code switching were expected to be more long term, or even permanent. &nbsp;It still raises the original question whether this is intended or if the compiler just hasn’t gotten to the point of detecting this case as well.<div class=""><br class=""></div><div class="">-d<br class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 19, 2016, at 7:57 AM, Charlie Monroe &lt;<a href="mailto:charlie@charliemonroe.net" class="">charlie@charliemonroe.net</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="">Hi David,<div class=""><br class=""></div><div class="">I find these warning useful at times, annoying at others - like in your case.</div><div class=""><br class=""></div><div class="">I've personally come to a solution where I've declared a struct that contains these values:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Debug {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;<font color="#ba2da2" class="">static</font></span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> useFoo = </span><span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">true</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">Debug</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">useFoo</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"yes"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">} </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"no"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">I've come to realize that this has a huge advantage of keeping all the debugging options together within the entire project and it eliminates any warnings.</span></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Oct 19, 2016, at 1:50 PM, David Goodine via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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="">Hey all,<div class=""><br class=""></div><div class="">I don’t know if this is really an ‘evolution’ topic per se, and I’m not on Swift Dev, but thought someone here could shed some light on this.</div><div class=""><br class=""></div><div class="">Often when developing code, if I need create mode switches (constant Bools) so that I can move back and forth between different features/implementations for testing, developing experimental features, migration, etc. &nbsp;Currently if I write the following:</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">let useFoo = true</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">if useFoo {</font></div><div class=""><font face="Courier" class="">// Foo code</font></div><div class=""><font face="Courier" class="">} else {</font></div><div class=""><font face="Courier" class="">// Non-Foo code</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><br class=""></div><div class="">I will get compiler warnings either way that there’s unreachable code based on the value of useFoo. &nbsp;That makes sense in most cases, but in some cases I need to leave the code as is for a while, and I hate leaving long-standing compiler warnings in production code. &nbsp;(If it’s yellow, you need to pay attention to it.) &nbsp;So I poked around and discovered that if I use the following declaration of useFoo, the warnings go away.</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">let useFoo = { return true }()</font></div><div class=""><br class=""></div><div class="">So, the question is, is this intentional? The compiler could certainly ascertain that useFoo will always be true and carry out the same dead code detection as for the first declaration. &nbsp;If this isn’t intentional, and the compiler may at some point optimize away the closure and trigger dead code warnings, I might come up with a proposal that there is some idiom that allows one to do the above without the warnings. &nbsp;I’m really not a fan of #define (because it’s just butt-ugly in such a beautiful language), but its existence is unavoidable for some cases. &nbsp;</div><div class=""><br class=""></div><div class="">And, as I write this, I realized I haven’t tried declaring useFoo as var, but I expect that would trigger a warning that useFoo is not modified and should be defined by let. &nbsp;I think this is a use case that, for practical purposes, should be covered to allow this type of evolution of code without generating warnings. &nbsp;If the current behavior is intentional and going to stay, then that’s probably the best solution.</div><div class=""><br class=""></div><div class="">-d</div><div class=""><br class=""></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></body></html>