Why not allow empty code blocks?

Steven D'Aprano steve at pearwood.info
Sat Jul 30 11:07:28 EDT 2016


On Sat, 30 Jul 2016 10:31 pm, Rustom Mody wrote:

> What makes you think I wanted to print those numbers??

The fact that you called print.


> Maybe I wanted a list of 10 None-s??

The idiomatic Python way of doing it would be:

[None]*10

The beginner's way of doing it would be:

[None, None, None, None, None, None, None, None, None, None]

The premature optimizer would do the same as the beginner.

Somebody who thinks of list comprehensions as the only hammer in their
toolbox would write:

[None for i in range(10)]

Confused Lisp programmers would write:

list(map(lambda ignore_me: None, range(10)))


But the idea that somebody might call print(i), and put up with its HIGHLY
VISIBLE side-effects, just for the return result of None, instead of just
writing None, is too implausible to take seriously. If I saw such code, I'd
immediately submit it to The Daily WTF.



-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list