About switch case statements...
bearophile
bearophileHUGS at lycos.com
Mon Nov 16 09:56:11 PST 2009
Don:
> (1) "case A, B, C:" implies a relationship between A, B, and C, which
> might not exist. They may have nothing in common.
It's just a list of things, it's a syntax people adapts too. Here too there's no relationship between x and foo:
int x, foo;
> (2) it's an extremely common coding style in C, C++.
If automatic fall-through becomes a syntax error, then allowing it for empty case statements is a special case of a special case. This kind of complexity kills languages. As they say in Python Zen:
Special cases aren't special enough to break the rules.
And this is D.
> (3) it's more difficult to read.
You can put items in one column anyway, so instead of:
case someverylongcase:
case anotherverylongcase:
case thelastverylongcase:
You can write:
case someverylongcase,
anotherverylongcase,
thelastverylongcase:
This is not so unreadable.
----------------------
Justin Johansson:
> Actually I quite like the brevity you propose but would
> it be a challenge for the comma operator?
That's already standard D syntax :-)
http://codepad.org/ByvTAs27
Bye,
bearophile
More information about the Digitalmars-d
mailing list