New user's initial thoughts / criticisms of Python

Jonathan jtcegh at
Sat Nov 9 23:44:37 CET 2013

On Saturday, November 9, 2013 8:27:02 AM UTC-5, Joshua Landau wrote:

> `select` is quite an odd statement, in that in most cases it's just a
> weaker variant of `if`. By the time you're at the point where a
> `select` is actually more readable you're also at the point where a
> different control flow is probably a better idea. Things like
> dictionaries or a variables pointing to functions are really useful
> and can be encapsulated in a class quite well. This is a bit more
> advanced but largely more rigorous.
> But most of the time the idea is just that an `if` is more explicit,
> and it's not like a `case` statement can be optimised as it can in
> lower-level languages with simpler datatypes.

The C switch statement is very limited.  The select statement in the dialect of BASIC I regularly use is more flexible.   It's more concise on long if chains because it elides the "end if"s.  But the use of indentation for blocks and the "in" operator certainly reduce the need for it in Python.

In pythonic syntax:

select <expression0>:
  case <case expression>,[<case expression>],:
  case else:

where <case expression> is one of

a) <expression1>

which is equivalent to:   elif <expression0> = <expression1>:

b) <binary-operator> <expression2>

which is equivalent to:   elif <expression0> <binary-operator>

Note that:
 "elif" is actually "if" for the first case in the select.
 control exits at next case, no need for breaks.
 expression0 is only evaluated once and stored in an anonymous temporary variable.

The switch statement in (the language) go is similar, except that <expression0> defaults to true and it doesn't elide <expression0> in the case statements.

Dictionaries can't handle the uses where expression0 is constant and the case expressions are not.
Function variables beg the question.  How did you decide what to assign to the variable?

I'd use this select if it was in Python, but I don't see much need for it.


More information about the Python-list mailing list