FAQ

On Fri, Sep 11, 2015 at 6:07 AM, wrote:
On Thu, Sep 10, 2015, at 12:48, Chris Angelico wrote:
Having assignment be a statement (and therefore illegal in a loop
condition) makes sense. Having it be an expression that yields a
useful or predictable value makes sense. Having it be an expression,
but not returning a value, doesn't.
Why not? Having it not return a value (and thus be illegal in places
that expect a value), but be legal in places like C's comma operator or
Lisp's progn that do not use the value, would make logical sense. Your
while loop could be written as something like "while (ch = getchar();
ch): ..."

The main purpose of this would be to prevent you from using it where a
boolean is expected, which wouldn't be necessary if Python hadn't
repeated C's mistake of spelling it "=".

I didn't say it doesn't make _technical_ sense to have an expression
without value, but it doesn't make any _useful_ sense. In previous
posts I consciously avoided this wording, but I'm going to say it, and
clink my pun jar: There's no value in doing it that way.


In order to make this valueless expression useful, you have to first
have some sort of expression that consists of two subexpressions,
where one of them is ignored. (Like C's comma operator.) Why do it?
Why not simply have the expression yield a useful value - or else not
be an expression, such that you have two _statements_?


ChrisA

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2017 Grokbase