[Issue 6176] [tdpl] Cannot use string variables in case expressions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 16 14:40:43 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6176
--- Comment #14 from Don <clugdbug at yahoo.com.au> 2012-01-16 14:40:36 PST ---
(In reply to comment #11)
> I'm just going to interject here.
>
> I don't understand why anyone sees the need to limit the switch construct in
> any way. Why force it to use compile-time values? Why force it to support
> primitives only?
Switch statements are easy to reason about, because they are controlled by a
single expression. If the values of the cases are allowed to vary, they are no
easier to understand than a sequence of if() statements, *but* that's not what
it looks like -- it's really deceptive.
int a = 2;
for(;;)
{
switch(7)
{
case a:
return;
case 7:
a = 7;
break;
}
}
> A full-blown, generalized switch would greatly improve D's expressiveness, and
> would cater to functional programmers. Functional languages have shown that
> pattern matching (which is essentially just a generalized switch, or -- as I
> like to call it -- switch done *right*) is extremely useful to write short and
> concise code, especially the ML family of languages (SML, OCaml, F#, etc).
But functional languages don't have variables in their case statements!
In this case, it's not more expressive - it's less expressive. It's simply
syntax sugar for a sequence of if() statements.
A switch statement says more: only one side of the comparison is varying. The
restriction is useful because it allows you to think at a higher level.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list