http://d.puremagic.com/issues/show_bug.cgi?id=6176



--- Comment #13 from bearophile_h...@eml.cc 2012-01-15 11:11:43 PST ---
(In reply to comment #11)

> I don't understand why anyone sees the need to limit the switch construct in
> any way.

There are two very different use cases in D here. If you want to implement a
C-style finite state machine switching on a enum integer you want the compiler
to squeeze of the very last bit of performance out of the code.

If you are writing functional-style code in a not performance-critical part of
the program you prefer a very flexible switch.

In theory a well implemented switch is able to work for both use cases, but
compiler practice is often different from theory, and what is good for
single-instruction-conscious code is often not the best for the other use case. 

Requiring all switch cases to be compile-time constants gives some guarantees.
Sometimes you only think a value is a compile-time constant, while it is not,
and if the compiler doesn't warn you, you risk having a lower performance.
Strings at compile-time in theory allow the compiler to use smarter and more
faster strategies to find the various cases.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to