[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 --- Comment #1 from bearophile_h...@eml.cc 2010-06-21 03:17:29 PDT --- Sean Kelly and Michel Fortin have shown some code examples. This D code: switch (x) { case 1: case 2: case 3: case 4: doSomething(); break; default: whatever(); } With the new proposal can be translated like this (this is already D syntax): switch (x) { case 1, 2, 3, 4: doSomething(); break; default: whatever(); break; } C/C++ programmers that will want to use D will have to learn the new rule that says: "In D there is no automatic case fallthrough". But allowing the fallthrough when there are no statements after the label is a special case to the general rule that they have to learn: ", unless there are no statements inside the case.". Special cases are bad in a programming language, they make manuals longer, require more time and energy for the programmer to learn them, make the compiler more complex and more buggy, and often slow down the programming even whey they were created to give a handy special case. - This D code gives a little more problems: switch (x) { case 1: .. case 10: case 22: .. case 32: case 52, 64: doSomething(); break; default: whatever(); } With the new proposal it can be translated like this (this is new syntax), that considers a closed range of values one of the possible items of the list of cases: switch (x) { case 1: .. case 10, case 22: .. case 32, 52, 64: doSomething(); break; default: whatever(); } Or just like this (this is normal D syntax): switch (x) { case 1: .. case 10: goto case; case 22: .. case 32: goto case; case 52, 64: doSomething(); break; default: whatever(); } This shorter syntax (that uses a single 'case' statement) is now not available: switch (x) { case 1 ... 10, 22 ... 32, 52, 64: doSomething(); break; default: whatever(); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 Andrei Alexandrescu changed: What|Removed |Added CC||and...@metalanguage.com --- Comment #2 from Andrei Alexandrescu 2010-06-21 06:30:56 PDT --- This is all unnecessary aggravation. I don't think it's complicated for anyone to understand that there's a requirement to insert a "break;" (or another control flow statement) in places where a "break;" should be inserted anyway. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 --- Comment #3 from bearophile_h...@eml.cc 2010-06-21 11:19:01 PDT --- Answer to Comment 2: I agree that it's easy for people to understand that there's a requirement to insert a break or similar. This is what I have written in the Description. But this was not the point of my Comment 1. In Comment 1 I was talking about the *exception* to that easy rule. What I was trying to express is that I don't like such exception to the rule. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 --- Comment #4 from bearophile_h...@eml.cc 2010-09-28 15:35:45 PDT --- Walter has now vaguely accepted to require a control statements at the end of each case. But some people have asked for an exception to that rule, when a case is empty. This bug 4349 is against that exception. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 Jonathan M Davis changed: What|Removed |Added CC||jmdavisp...@gmx.com --- Comment #5 from Jonathan M Davis 2010-09-28 16:21:29 PDT --- I think that the exception makes good sense and wouldn't mind having it but that it's not particularly necessary. Thanks to ranged case statements and the like, the need for multiple case statements which all fall through to a single block of code is greatly reduced if not outright eliminated. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 Brad Roberts changed: What|Removed |Added CC||bra...@puremagic.com --- Comment #6 from Brad Roberts 2012-01-01 20:45:10 PST --- This one is ready to be closed, right? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 4349] Deprecate automatic case fallthrough
http://d.puremagic.com/issues/show_bug.cgi?id=4349 bearophile_h...@eml.cc changed: What|Removed |Added Status|NEW |RESOLVED Resolution||FIXED --- Comment #7 from bearophile_h...@eml.cc 2012-01-02 04:35:19 PST --- (In reply to comment #6) > This one is ready to be closed, right? I don't like a lot the presence of a special case to the D rule that implicit fall-through is disallowed in D (this code compiles): void main() { int x; switch (x) { case 1: /* x++; break; */ case 2: break; default: break; } } But I presume you are right, so I close this issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---