Re: "no variable or argument declarations are necessary."
- From: Will McGugan <news@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 02 Oct 2005 22:08:04 +0100
James A. Donald wrote:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read
"no variable or argument declarations are necessary."
Surely that means that if I misspell a variable name, my program will mysteriously fail to work with no error message.
If you don't declare variables, you can inadvertently re-use an variable used in an enclosing context when you don't intend to, or inadvertently reference a new variable (a typo) when you intended to reference an existing variable.
What can one do to swiftly detect this type of bug?
A variable has to be assigned to before it is used, otherwise a NameError exception is thrown..
>>> a + 1 Traceback (most recent call last): File "<interactive input>", line 1, in ? NameError: name 'a' is not defined >>> a = 1 >>> a + 1 2
Typos in variable names are easily discovered unless the typo happens to exist in the current context.
Will McGugan
--
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz")
.
- References:
- "no variable or argument declarations are necessary."
- From: James A . Donald
- "no variable or argument declarations are necessary."
- Prev by Date: Re: "no variable or argument declarations are necessary."
- Next by Date: Re: "no variable or argument declarations are necessary."
- Previous by thread: Re: recursive function
- Next by thread: Re: "no variable or argument declarations are necessary."
- Index(es):
Relevant Pages
|