Can global variable be passed into Python function?
marko at pacujo.net
Sat Mar 1 00:06:38 CET 2014
Mark Lawrence <breamoreboy at yahoo.co.uk>:
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.
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
And I sometimes run into convoluted factory (anti)patterns whose sole
purpose is to avoid straightforward switch statements in a decoder.
More information about the Python-list