[Tutor] Re: case/switch, etc.

Magnus Lycka magnus@thinkware.se
Tue, 15 Oct 2002 10:59:55 +0200


At 13:52 2002-10-12 +0100, James.Rocks@equant.com wrote:
>In (some) other languages SWITCH/CASE has been touted as an advance on what
>there was before ... that in mind I thought python might reasonably be
>expected to feature it.

Python tries to avoid redundant features.
If you want a lot of redundant features
(and the confusion that follows) go for
Perl or PHP.

The power in Python does not stem from
an extensive feature list, but from its
simplicity.

The richness in Python is in its standard
library, and in its data types. The syntax
is deliberately simple.

Sure, switches are slightly shorter than
if-elif-else for the cases where they fit.
But why have a special syntax for a subset
of the situations covered by if-elif-else?

Besides, with Python's completely consistent
indentation, it would not be so simple to
make switches look pretty. Look at how ugly
and inconsistently indentation is used for
switches in C programs.

It's like C's for-loop, which is a mutated form
of a clean iterations loop as they look in Pascal,
Fortran etc, to just a more compact, syntactic
variation of a while loop.

It doesn't really add any new feature, just a
short-form for a special case.

When I first saw it, I thought it was a very
cool feature, but then I've seen a mistakes
and confusion in using it, and Python's for
loop really adds something which the while
loop doesn't do in a simple way.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se