"no variable or argument declarations are necessary."

Jean-François Doyon jfdoyon at methane.ca
Sun Oct 2 17:11:13 EDT 2005


Wow, never even occured ot me someone would have a problem with this!

But, this might help:

http://www.logilab.org/projects/pylint

In more detail:

 > Surely that means that if I misspell a variable name, my program will
 > mysteriously fail to work with no error message.

No, the error message will be pretty clear actually :) You are 
attempting to use a variable that doesn't exist!  This would be the same 
type of message you would get from a compiled language, just at a 
different point in time (runtime vs. compile time).

 > If you don't declare variables, you can inadvertently re-use an
 > variable used in an enclosing context when you don't intend to,

Possible, though good design should always keep anysuch situation at 
bay.  Python is OO, hence scoping should rarely be a problem ... globals 
are mostly evil, so the context at any given time should be the method, 
you'd need a fairly big and complex method to start loosing track of 
what you called what ... Also, a good naming convention should keep this 
at bay.

Also, because things are interpreted, you don't (normally) need to put 
extensive forthought into things as you do with compiled languages.  You 
can run things quickyl and easily on demand, a misnamed variable will be 
clearly indicated and easily solved in a matter of minutes.

Using a smart IDE might also help prevent such problems before they occur?

Hope you enjoy python :)

J.F.

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?
> 
> 
> --
> http://www.jim.com



More information about the Python-list mailing list