variable declaration

Steve Holden steve at holdenweb.com
Mon Feb 7 17:51:08 EST 2005


Alexander Zatvornitskiy wrote:

> Привет Alex!
> 
> 05 февраля 2005 в 17:00, Alex Martelli в своем письме к All писал:
>  >>  AM> The fact that in Python there are ONLY statements, NO
>  >>  AM> declarations,
>  >> What is "global"? Statement? Ok, I fill lack of "var" statement:)
>  AM> 'global' is an ugly wart,
> 
> Ok,
> ===
> def hi():
>   print "hello!"
> ===
> What is it? Statement or declaration? After interpreter see this lines, it add
> information about function "hi" and it's body to his memory. Look at this:
>   var S
> Interpreter see this line and add information about variable S to the memory. I
> don't find big difference.
> By the way keyword "def" is as bad as "var", from your point of view? :)
> 
If your colloquial English is good enough to understand the word 
"bollocks" then you might begin to realize how irritating your arguments 
are becoming.

If, as you suggest, def were a declaration, then it should either not be 
possible to write

     if __debug__:
         def func(x):
             print x, "is bollocks"

or, if it were possible, then func would have a code object bound to it 
whether or not __debug__ were true.

In point of fact this is perfectly legal Python, which results in no 
binding to the name func when __debug__ is false, precisely *because the 
def statement is executable* - and it is so by design.

>  AM> to all intents and purposes working "as if"
>  AM> it was a declaration.  If I had to vote about the one worst formal
>  AM> defect of Python, it would surely be 'global'.
> Second worsest - 'def'? :)
> 
The reason global is a wart can clearly be seen in the following example:

  >>> x = 3
  >>> def f(tf, v):
  ...   if tf:
  ...     global x
  ...   x = v
  ...
  >>> f(0, 5)
  >>> x
5
  >>>

This makes it apparent that the global statement is *not* executable, 
the only one in the language that is not.

[...]
> 
> But, I am friendly, even with my opponents. I think it is my good trait.
> 
You are, of course, entitled to your opinion, self-serving though it may 
be. A friendly idiot is still an idiot.

[...]

> But I still think declaration of variables is good idea. But with shorter
> syntax. May be, smth like this: ~S, or `S or .S, or S`, S~ , S. , and so on. Of
> course it must be optional feauture: use it if you want or don't use if you
> don't want.
> 
Why not make it even shorter by omitting it altogether. Oh, sorry, it 
can be as short as you want as long as it isn't actually zero length? 
This is insanity ...
> 
[...]
> 
> Don't be so ... I don't find the equivalent english word. Smth like: Take it
> more easy.
> 
Please don't insult the martellibot. He did, after all, write "Python in 
a Nutshell" and co-edited the "Python Cookbook", and he has established 
a reputation with his consistent long-term contribution to Python and 
this newsgroup. Instead, ask yourself why your remarks engender such a 
response from a pillar of the Python community. What are your credentials?

regards
  Steve
-- 
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005                      http://www.pycon.org/
Steve Holden                           http://www.holdenweb.com/



More information about the Python-list mailing list