Evaluating python - a question

Grant Griffin not.this at seebelow.org
Fri May 18 16:56:36 EDT 2001


In article <9e100t$8e1$1 at news.netmar.com>, alan.prescott at nospam.jarrold.com
says...
>
>I'm just starting to look at Python as a language but there's one thing that
>is bothering me regarding using it for large projects and that's the ease
>with which I can put in a simple typo and not have it spotted by the
>compiler. For example;-
>I create a class ...
>
>class person:
>
>This class has an attibute of forename so
>
>me = person()
>me.forename = 'Alan' 
>
>is Ok but a simple typo (especially with my keyboard skills) of
>
>me.froname = 'Fred'
...

This sort of thing is very rare, in my experience.  However, a pretty _common_
thing is:

    me.forename = 'Alan'

    print me.froname        # raises error in Python

that is, an attempted read of a non-existent variable, due to a typo.

I think Python's approach to this problem is truly inspired.  The "no writie, no
readie" thing catches nearly all such typos, yet you still don't have to declare
variables.  (Like "blocks-by-indenting", this idea is so simple that most other
languages never thought of it.)

Now, don't get me wrong: declaring variables isn't so bad in general, but it
really doesn't fit into a language which uses dynamic data typing.

In contrast, Perl allows you either to let variables silently spring into
existence (with zero-ish values automically supplied), or to be treated as an
error.  Flexibility is nice, but as Tim has said, "There should be one--and
preferably only one--obvious way to do it.  <<Kama Sutra>>  When I used to write
Perl (before I found Python), I much preferred to have undeclared variables
treated as errors: otherwise, letting them spring into existence was such an
inviting noose that I found it pretty hard not to hang myself.  (Or was it just
masochism, like the use of Perl <wink>?)

Anyway, with Python's system, I virtually never have a problem of this sort. 
Or, as a wise man once said while selling spaghetti sauce: "Try it, you'll like
it!"

my-typos-consist-mostly-of-forgetting-to-append-':'-to
   -decision-statments-that-don't-conceptually-need-them
   -<wink>-ly y'rs,

=g2

_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com




More information about the Python-list mailing list