tom at dtsam.com
Mon Jan 31 20:34:11 CET 2005
<Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org> wrote in message
news:MSGID_2=3A5025=2F3.131_41fde342 at fidonet.org...
> Hello All!
> I'am novice in python, and I find one very bad thing (from my point of
> language. There is no keyword or syntax to declare variable, like 'var' in
> Pascal, or special syntax in C. It can cause very ugly errors,like this:
> while epsilon<10:
> print S
> It will print zero, and it is not easy to find such a bug!
> Even Visual Basic have 'Option Explicit' keyword! May be, python also have
> a feature, I just don't know about it?
Python *does* require that your variables be declared and initialized before
you use them. You did that with epsilon=0 and S=0 at the top. It is
unfortunate, however, that the statement epselon=epsilon+1 also declares a
new variable in the wrong place at the wrong time. Such mispellings are a
*common* error caught instantly in languages that require a more formal
Another irksome sitiuation is that while Python does enforce strict type
checking, you can re-declare variables and morph them in the middle of
S = 0 # It's an Integer!
S = S + 'Hello' # No can do! Strong type checking forbids this.
S = 'GoodBye' # Whoops - Now it's a string! Unfortunately
This seemingly demolishes all the good reasons one has for wanting strict
That second example is just bad programming practice and easy to avoid. The
problem you point out in your code, however, hurts! Was that an I, an l or a
1 in the variable name?
Hey! - I like Python a lot.
But nothings perfect
More information about the Python-list