<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 17 February 2014 18:43, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On 2/16/2014 7:39 PM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think a really useful construct could be made out of switch, but it seems that<br>
it won't happen because it must support C code unchanged.<br>
</blockquote>
<br></div>
I tend to agree with Andrei on this - the proposals aren't fundamental or game changing, and are kinda just bouncing the rubble around (po-tay-to vs po-tah-to).</blockquote><div><br></div><div>Refer to my other reply wrt the 'rubble' concept.</div>
<div><br></div><div>I think a quality implementation would be fairly game changing. A properly scoped and fully featured switch/select/match statement would result in some radical simplifications of code all over the place.<br>
</div><div>Sequential if/if else statements might see a decline, and there would be far less repetition of terms in the conditional statements.</div><div>If switch (or something like it) were massaged to be as nice to use as foreach is, I think you'll find it will be used all over the place.</div>
<div><br></div><div>Note: I probably wouldn't be exaggerating if I said foreach is the main reason I started looking into D in the first place. When I first glanced over the D feature list, I could have easily closed the browser tab, but that's the thing that kept me reading...</div>
<div>I've said it before, and I'll say it again, I think these things are _so fundamental_, that their importance is often underestimated, and often overlooked.</div><div>Could you imagine D without foreach? In retrospect, you can't. But If you were arguing from a position where you never had anything like foreach to the value of it's inclusion, it wouldn't look anywhere near as strong as it does in retrospect.</div>
<div><br></div><div>The idea of eliminating many unsightly if/else if blocks is very appealing to me.</div><div>Just scanning through my code, I can imagine so many instances where my code would become more readable.</div>
<div>People usually use switch today for the same reason, but it's always a hard call... is the crappiness of 'switch' a quantifiable improvement over the if/else if sequence? I find myself asking that question all the time. That's why I brought it up.</div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
> Isn't that the entire point of final switch?<br>
> Why introduce final switch to address that, then do this aswell?<br>
<br></div>
Implicit in your questions is switches will only be used on enums, i.e. all the values a type can be are known to the compiler. This is only true for a smallish subset of types that are switched on.<br>
<br>
final switch : for enums<br>
<br>
default : for everything else<br>
</blockquote></div><br></div><div class="gmail_extra">But... that's like making it an error for an if() to appear without an else statement. It's _exactly_ like that.</div><div class="gmail_extra">I don't think I couldn't disagree more.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Imagine:</div><div class="gmail_extra"><br></div><div class="gmail_extra">if(condition)</div><div class="gmail_extra">{</div><div class="gmail_extra">  doSomething();</div>
<div class="gmail_extra">}</div><div class="gmail_extra">else</div><div class="gmail_extra">{}</div><div class="gmail_extra"><br></div><div class="gmail_extra">blah blah.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
if(failed)</div><div class="gmail_extra">{</div><div class="gmail_extra">  handleError();</div><div class="gmail_extra">}</div><div class="gmail_extra">else</div><div class="gmail_extra">{}</div></div>