Abstract and concrete syntax

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Jun 9 00:31:12 EDT 2005


David Baelde wrote:

> Statements are not expressions.
> 
> I feel there are some real problems here. But I can't find anything
> absolutely unsolvable.

There's no doubt that these problems could be solved in
a technical sense, but the real issue is whether the
resulting code would be *readable*. One of Python's
major strengths is that its code is usually very easy
to read, even if it means being a bit more verbose at
times than strictly necessary.

All the proposals I've seen for statements-in-expressions
in Python (and there have been quite a few) have been a
disaster in the readability department

> PEP #308 was about having a ternary (?:)
> operator for expression level conditional, pythonists rejected it.

Actually, it was really Guido who rejected it, because
Pythonistas failed to reach a consensus on syntax, and he
wasn't really hot on the idea in the first place. If he
had really wanted it, he would have just picked a syntax
himself.

> More generally, I think there is no abstract distinction between
> statements and expressions.  Everything is an expression, can be evaluated
> to a value.

That's true in a functional language, but Python is not a
functional language. In imperative programming, often you just
do something for its side effect, and there's no obvious value
to return. Forcing everything to return a value just for the
sake of conceptual purity is an artificiality, in my view.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list