why pass statement?

M

M-a-S

Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None
 
A

anton muhin

M-a-S said:
Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None
No. None is just a value (now variable), not a statment.

hth,
anton.
 
P

Peter Hansen

M-a-S said:
Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None

For readability. Pass makes more sense. You seem to think minimalism
is inherently good... (?)

-Peter
 
J

John Roth

M-a-S said:
Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None

You don't actally need Pass. A docstring is sufficient:

class C:
"this is a class"

while True:
"loop de loop de loop"

John Roth
 
H

Hans Nowak

M-a-S said:
Why is there the pass statement? I think, the expression statement would be enough:

class C:
None

while True:
None

'pass' is a no-op statement that, according to the tutorial, is used when a
statement is required syntactically but the program requires no action.

Your code, using None, has the same effect. However, there's a slight
difference in the bytecode that is generated:
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE 1 0 LOAD_GLOBAL 0 (None)
3 POP_TOP
4 LOAD_CONST 0 (None)
7 RETURN_VALUE

This is probably irrelevant, but it wouldn't be correct to say that using pass
is exactly the same as using None.

HTH,
 
A

Andrei

Originally posted by M-A-S
A good idea! Thanks!
(e-mail address removed)"]news:[email protected]
m[/url]...
You don't actally need Pass. A docstring is sufficient:
class C:
"this is a class"
while True:
"loop de loop de loop"
John Roth



I find "pass" shows that something could be there, sort of "insert stuff
here if you like/need to". A string as such doesn't have that effect.
Obviously you could always make up some useless statement instead of
pass, but pass just looks more elegant IMO. You probably should use it
if you plan on showing your code to others.


--
Contact info (decode with rot13): (e-mail address removed)
Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP.


Posted via http://dbforums.com
 
B

Bruno Desthuilliers

M-a-S said:
> A good idea! Thanks!

Not a so good idea, since the pass statement is explicit (and explicit
is better than implicit).

My 2 explicit eurocents
Bruno
 
M

M-a-S

Hans Nowak said:
'pass' is a no-op statement that, according to the tutorial, is used when a
statement is required syntactically but the program requires no action.

I know. I just state that there is NO need for it. Just define in __builtins__
pass = None and that's it.

BTW Algol-68 used 'skip' for both purposes (no action and no data).

Your code, using None, has the same effect. However, there's a slight
difference in the bytecode that is generated:

1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
1 0 LOAD_GLOBAL 0 (None)
3 POP_TOP
4 LOAD_CONST 0 (None)
7 RETURN_VALUE

This is probably irrelevant, but it wouldn't be correct to say that using pass
is exactly the same as using None.

HTH,


That's just a question of optimization.

And thank you for showing me how to dig to the code!

M-a-S
 
M

M-a-S

Andrei said:
I find "pass" shows that something could be there, sort of "insert stuff
here if you like/need to". A string as such doesn't have that effect.
Obviously you could always make up some useless statement instead of
pass, but pass just looks more elegant IMO. You probably should use it
if you plan on showing your code to others.


I know, I do :) It's too late to make a revolution.
 
T

Terry Reedy

JCM said:
would be enough:



Because emacs python-mode knows to dedent the next line after a pass
:)

Nice.

pass is the guaranteed-to-do-nothing identity statement (function
operating on the interpreter state). def f(): pass generates a
*miminal* function object with a *minimal* code object. This is at
least potentially useful for testing or investigating the
implementation. The alternative of an expression statement adds code
to the code body. The alternative of a doc string generates a string
object attached somewhere to the no-longer-minimal function or code
object. Indeed, the way to test the effect of either alternative is
to start with the minimum and then define f2 and look for the
difference -- as one of the earlier posters in this thread did do
(using dis module to 'look') for the None expression.

Terry J. Reedy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top