Can global variable be passed into Python function?

Albert van der Horst albert at
Mon Mar 10 15:12:59 CET 2014

In article <87sir2et1d.fsf at>,
Marko Rauhamaa  <marko at> wrote:
>Mark Lawrence <breamoreboy at>:
>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

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.
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar& &=n

More information about the Python-list mailing list