Why not allow empty code blocks?

D'Arcy J.M. Cain darcy at Vex.Net
Sat Jul 23 09:54:41 EDT 2016


On Sat, 23 Jul 2016 16:13:58 +0300
Marko Rauhamaa <marko at pacujo.net> wrote:
> "D'Arcy J.M. Cain" <darcy at Vex.Net>:
> > It's ambiguous to the reader what was actually meant.  Forcing a
> > "pass" there shows the reader that the empty block was not a
> > mistake.
> 
> Just let the syntax speak for itself. The code means what the language
> definition says it means.

Exactly so given this...

for x in sequence:
print("Something")

If the language allowed that then we know exactly what the programmer
said.  What we don't know is what the programmer meant.  The above is a
simple and obvious statement but real code is more complicated.  Add a
few comments and a little nesting and what used to be obvious isn't.
The interpreter would still know what the programmer said but without
the pass requirement it is easier for it to be not what he meant.

Python has some nice features like this one that protect the programmer
and allow much faster development because there is a safety net.  If
you like knives without handles you know where to find Perl.

Gotta go.  The metaphor police are at the door.

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:darcy at Vex.Net
VoIP: sip:darcy at Vex.Net



More information about the Python-list mailing list