In article <87sir2et1d....@elektro.pacujo.net>,
Marko Rauhamaa  <ma...@pacujo.net> wrote:
>Mark Lawrence <breamore...@yahoo.co.uk>:
>
>> http://c2.com/cgi/wiki?SwitchStatementsSmell
>
>Your brief summary, please, Mark?
>
>Anyway, the first 1000 lines or so that I managed to read from that page
>stated a valid principle, which however doesn't invalidate the existence
>of a switch statement.
>
>A colleague of mine taught me decades back that the whole point of OO
>was the avoidance of if and switch statements. So if your code has an if
>or switch statement, chances are you are doing something wrong.
>
>I agree.
>
>However, like all other maxims, that principle, too, has exceptions. Two
>recurring examples are parsers/decoders and state machines. Sure, you
>can implement states beautifully with objects/classes (and I do do that
>when performance is not an issue), but having experimented with
>different implementation techniques (in C, C++ and Java), I have
>concluded that switch statements are often unbeatable in performance and
>clarity.

I can't see why parsers decoders are any different.
The Pentium assembler in my ciforth's ``forth.lab'' library has not
a single if statement and I reckon it is a superior design.
(State is kept in an ai blackboard fashion in bitmaps.)
Forth has of course a built in "look it up, then execute it",
which could be regarded as a giant switch.

>
>And I sometimes run into convoluted factory (anti)patterns whose sole
>purpose is to avoid straightforward switch statements in a decoder.
>
>
>Marko
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to