Necessity of ``pass''

forcer forcer at mindless.com
Mon Aug 23 17:32:44 EDT 1999


Hi there.

Lately, i've been thinking about Python. While it is an
exceptionally clean language, it has one very obvious wart:
The ``pass'' statement.

To quote the reference manual:

   pass is a null operation -- when it is executed, nothing
   happens. It is useful as a placeholder when a statement is
   required syntactically, but no code needs to be executed, for
   example:

   def f(arg): pass    # a function that does nothing (yet)

So it happens that Python has places where semantically nothing
should be done, while syntactically it requires a statement.

I consider this suboptimal.

As a solution, one could allow the following:
instead of

	if foo:
	   pass
	bar

one could write

	if foo:
	bar

Syntactically this does not introduce any ambiguity. The only
problem i see is that the "pass" version is more readable.

But...
Most of the time, people write

        if foo:pass
        bar

anyways so the "readability" does not suffer from leaving pass
out.

Also, the requirement for pass makes it impractical to comment
out parts of an if expression, like in

        if foo:
	   # baz
	   # qux
	bar

The new syntax would even allow a smooth transition, or
coexistence of both versions. Pass can be retained to keep the
possibility for a explicit do-nothing statment, while it's just
not mandatory anymore.

I'd like to see such a change in the Python language, so it'll be
even cleaner than it was before.

I hope my opinions and thoughts are of value to you,
       --forcer

-- 
((email . "forcer at mindless.com")       (www . "http://forcix.cx/")
 (irc   . "forcer@#StarWars (IRCnet)") (gpg . "/other/forcer.gpg"))




More information about the Python-list mailing list