Editions Ideas
Vladimir Panteleev
thecybershadow.lists at gmail.com
Sun Jan 11 14:15:21 UTC 2026
On Sunday, 11 January 2026 at 06:47:42 UTC, IchorDev wrote:
> One big thing I'd love would be for us to stop requiring a
> `break` at the end of each `case`; instead a case should
> default to breaking at the end, which is what you want 99% of
> the time. We already require an explicit `goto case` for
> fall-through, and give an error otherwise, so this won't break
> existing code.
I don't think this is going to happen due to C source
compatibility being one of the design goals of D - if you paste
in C code, it should either compile and work in the same way, or
fail to compile. C has implicit fallthrough (which is presumably
used intentionally) so it would be the exactly same syntax in
both C and D but which do very different things. The most likely
way towards improving this is probably a new pattern-matching
syntax to replace the C-like switch/case.
> Switch-case statements with short cases are so much nicer to
> read without all the redundant `break`s everywhere:
I've been doing this a lot:
```d
int x = 1;
string result = {
switch(x) {
case 0:
return "hi";
case 1:
return "bye";
default:
return "invalid code!";
}
}();
writeln(result);
```
More information about the Digitalmars-d
mailing list