allow line break at operators

Chris Angelico rosuav at gmail.com
Sun Aug 14 17:39:53 CEST 2011


On Sun, Aug 14, 2011 at 3:26 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Yes, print as a statement was a mistake. But assignment as a statement, not
> so much. Assignment as an expression in languages that have it tends to be
> associated with frequent errors.
>
> The way I see it, if something operates by side-effect, then it has no
> business being treated as an expression.

Wikipedia (that well-known authority) lists among examples of side
effects both "write data to a display or file" and "modify one of its
arguments".

This strongly implies that print() is a function that operates by
side-effect, just as the assignment operator (in languages in which it
is one) does. Treating "a=5" as an expression with the value 5 is no
more relying on side effects than having "print('asdf')" an expression
with the value None.

I believe that print-as-a-function is a Good Thing, mainly because it
can be used as an argument to such as map. Somewhat silly/trivial
example:
msgs=["Hello","World"]
list(map(print,msgs))

I'm aware that assignment-as-an-expression has plenty of risks
associated with it (the main one being the classic C issue of
assignment inside a conditional - a feature that I use frequently
myself, but which trips plenty of people up), which is a strong
argument for its remaining a statement, but side effects isn't on its
own.

ChrisA



More information about the Python-list mailing list