<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 18 February 2014 05:51, 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On 2/17/2014 5:49 AM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Refer to my other reply wrt the 'rubble' concept.<br>
</blockquote>
<br></div>
Sure :-)<div><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I think a quality implementation would be fairly game changing. A properly<br>
scoped and fully featured switch/select/match statement would result in some<br>
radical simplifications of code all over the place.<br>
</blockquote>
<br></div>
I have a real hard time seeing the proposed changes as radical or game changing.<div><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
If switch (or something like it) were massaged to be as nice to use as foreach<br>
is, I think you'll find it will be used all over the place.<br>
</blockquote>
<br></div>
foreach() is quite a large improvement, because by abstracting away the mechanics of iteration, code need no longer be aware of just what abstract type is being looped over. Furthermore, it eliminates several common sources of coding bugs.<br>


<br>
I'm not seeing this with changes in switch.<br></blockquote><div><br></div><div>I think abstracting away volumes of comparative matching logic is similarly interesting to eliminating tedious iteration logic. I find out-by-ones and bogus comparisons that I didn't spot is a very common class of bug (often just because matching code is long and repetitive).</div>
<div>Cut and paste, oops; you didn't spot that <= is actually >= from where you cut... or you didn't see it because the line is so long with repetition of the terms being compared that it's run off the right edge.</div>
<div>*disclaimer: peoples experiences may differ, this is my experience.</div><div><br></div>
<div>I agree, it's probably not as game-changing as foreach, but I think if you had it for a few years and became accustomed to writing much of that comparative logic in a simple and really obvious/less-repetitive way, you'd look back and wonder how you did without it. I suspect it's possible that the repetitive matching logic often found in if() statements represent a lot more code by volume than the iteration logic eliminated by foreach ever did in for loops.</div>
<div><br></div><div>I can't say how big a deal it is until I make a habit of applying it everywhere, but I can imagine the potential for massive improvement in readability, and elimination of many long if() expressions.</div>
<div><br></div><div>Comparing the savings:</div><div><br></div><div>for(int i=0; i<things.length; ++i)<br></div><div><div>-></div><div>foreach(i, thing; things)<br></div></div><div><br></div><div><br></div><div><div>
if(thing.member >= min && thing.member < max)</div></div><div>-></div><div>match(thing.member)<br></div><div> case(min..max)</div><div><br></div><div>If an 'else if' appears, the savings compound considerably.</div>
<div><br></div><div><br></div><div>I'm a practicality motivated programmer, I don't dream about futuristic features as much as I respond to the things that annoy me consistently on a daily basis. I don't like friction between me and getting my work done, and it's the little things that come up most often that tend to really bug me.<br>
</div><div>I'd like to think the languages foundational keywords should offer a good experience. You'll be typing them over and over again from now until the day you die. Looking at other languages, I think there's clearly a missed opportunity to do something a lot more modern and useful with the switch concept.</div>
<div><br></div><div>Rust does it nice. It's got a nice functional flavour to it.</div>
</div></div></div>