Long Live Python!

phawkins at spamnotconnact.com phawkins at spamnotconnact.com
Fri Jul 20 13:50:25 EDT 2001


>>>>> "DR" == Dennis Roark <denro at earthlink.net> writes:

DR> Lack of type safety; lack of forcing variable names to be
DR> declared before use.  (In a long program, how hard it is to
DR> find a bug that is simply the misspelling of a variable!)

Coming late to this discussion...

Python requires that a variable be assigned before use, and most typos
are caught by this requirement.  The one typo bug I can think of that
would not be caught is a typo in the lhs of an assignment, after a
previous assignment to the same variable.  And frankly, I've yet to
encounter one of these.  Current project, not my first python project,
is ~4000 lines of python, to give you some idea of my exposure.

EG:

    spaf = [1,2,3]
    for i in spam:
       dosomething
    
creates a traceback... as does

    spam = [1,2,3]
    for i in spaf:
       dosomething
                                       

However:

    spam = [1,2,3]
    dosomething to spam
    
    spaf = [7,8,9]
    dosomething to spam
    
is a silent bug.  Perhaps there ought to be a "strict" mode where
Python complains about variables that are assigned only once and never
used? 

I notice that most of us loathe multiple assignments to the same
variable -- a surprising amount of discussion on this newsgroup is
devoted to avoiding multiple assignments.  We prefer to write an
assignment just once, in a loop if appropriate.  Multiple assignment
statements hint that code is poorly thought out, or that a single
variable is being used for different purposes.

Patricia
-- 
Patricia J. Hawkins
Hawkins Internet Applications, LLC





More information about the Python-list mailing list