[Python-ideas] if expensive_computation() as x:
Steven D'Aprano
steve at pearwood.info
Sat Feb 15 00:58:39 CET 2014
On Fri, Feb 14, 2014 at 05:10:53PM -0500, random832 at fastmail.us wrote:
> On Fri, Feb 14, 2014, at 16:20, Steven D'Aprano wrote:
> > -1 on this. Python is not C and should not emulate it's mistakes, no
> > matter how tempting they seem :-)
>
> = as assignment is one of C's mistakes. I propose abandoning it in
> Python 4000.
>
> Absent that, assignments as expressions is no longer obviously a
> mistake.
I think it is. Mathematicians have been performing algorithmic
manipulations rather similar to programming for thousands of years, and
I do not believe that they have anything like assignment as expressions.
(Or if they do, they're in advanced fields which I have not come
across.) Instead, they either pre- or post-define the variables they
need.
# pre-define
y = something complicated related to x
z = function(y + 1/y)
# post-define
z = function(y + 1/y)
where y = something complicated related to x
They don't "in-define":
z = function(something complicated related to x as y + 1/y)
Mathematicians are notorious for inventing user-hostile but terse
syntax. If they don't do definitions-as-expressions, there is likely to
be a *really* good reason for it.
C using = for assignment-as-expression just compounds the problem, it
doesn't create the fundamental problem that sticking assignments in the
middle of an expression makes the expression hard for human beings to
parse.
--
Steven
More information about the Python-ideas
mailing list