[Python-ideas] Syntax: 'return: ...' expressions

Guido van Rossum guido at python.org
Wed Jan 21 02:16:12 CET 2015

On Tue, Jan 20, 2015 at 3:57 PM, Andrew Barnert <
abarnert at yahoo.com.dmarc.invalid> wrote:

> [...]
> I'm arguing the same thing: anyone who wants to embed statements inside
> expressions needs to understand why statements and expressions are distinct
> in the first place.
> Your old post that Franklin linked explains, given that we have that
> distinction, and significant indentation for statements, why any attempt to
> embed statements inside expressions is going to be inherently complex, and
> therefore likely a bad idea.
> But what I was hoping for was a post where you explained why we have that
> distinction in the first place. If Ruby and CoffeeScript don't need
> statements, why does Python? I think there's an answer, and it's part of
> the reason why code in Python tends to be more readable than in those
> languages (although, as you pointed out, CoffeeScript has other tangential
> problems), but I was hoping for _your_ answer.

Hm... Practically every language I knew before I designed Python had this
distinction built right into the grammar and other assumptions: Algol-60,
Fortran, Pascal, C, ABC. Even Basic. I was aware of the alternative design
choice: Algol-68 had statements-as-expression, and Lisp of course -- but I
wasn't a big Lisp fan, and in Algol-68 it was largely a curiosity for
people who wanted to write extra-terse code (also, IIRC the prevailing
custom was to stick to a more conservative coding style which was derived
from Algol-60).

So it's hard to say to what extent this was a conscious choice and to what
extent it was just tradition. But there's nothing necessarily wrong with
tradition (up to a point). I think it still makes sense that statements are
laid out vertically while expressions are laid out horizontally. Come to
think of it, mathematics uses a similar convention -- a formula is laid out
(primarily) horizontally, while a sequence of formulas (like a proof or a
set of axioms) is laid out vertically.

I think several Zen items apply: readability counts, and flat is better
than nested. There is a lot to be said for the readability that is the
result of the constraints of the blackboard or the page. (And this reminds
me of how infuriating it is to me when this is violated -- e.g. 2up text in
a PDF that's too tall to fit on the screen vertically, or when a dumb
editor breaks lines but doesn't preserve indentation.)

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150120/99f9a619/attachment.html>

More information about the Python-ideas mailing list