variable declaration

Alexander Alexander_Zatvornitskiy at
Sat Feb 5 09:42:10 CET 2005

Hi, Alex!

31 jan 2005 at 13:46, Alex Martelli wrote:

(sorry for the delay,my mail client don't highlight me your answer)

 AM> Since the lack of declarations is such a crucial design choice for
 AM> Python, then, given that you're convinced it's a very bad thing, I
 AM> suggest you give up Python in favor of other languages that give you
 AM> what you crave.
Well, I like Python. But, as every language I know, it have some bad sides
which I don't like. One of them in Python is lack of variable declarations,
another (this problem is common with C/C++) is:
>>>print 1/2
(I understand why it is so, but I don't like it anyway. Such behaviour also can
cause some hard-to-find-bugs)

 AM> issue for you.  Therefore, using Python, for you, would mean you'd be
 AM> fighting the language and detesting its most fundamental design
 AM> choice: and why should you do that?  There are zillions of languages
 AM> -- use another one.
Thank you for advice:)
 >> Pascal, or special syntax in C. It can cause very ugly errors,like
 >> this: epsilon=0 S=0 while epsilon<10:  S=S+epsilon
 >> epselon=epsilon+1 print S It will print zero, and it is not easy to
 >> find such a bug!
 AM> Actually, this while loop never terminates and never prints anything,
Oh, I don't find it:)
 AM> so that's gonna be pretty hard to ignore;-).
 AM> But, assume the code is
 AM> slightly changed so that the loop does terminate.  In that case...:

 AM> It's absolutely trivial to find this bug, if you write even the
 AM> tiniest and most trivial kinds of unit tests.  If you don't even have
 AM> enough unit tests to make it trivial to find this bug, I shudder to
 AM> think at the quality of the programs you code.

Thank you for advice again, I already use different tests in my work and I
found them usefull. But! I want to use Python for prototyping. I want to write
my algorithms on it, just to see they do almost they must to do. Next, I want
to play with them to understand their properties and limitations.
If sometimes such a program fall, or not very fast, or sometimes show wrong
results, it's not a big problem. So, I use Python like tool for prototyping.

After I debug the algorithm and understand it, I can rewrite it on C++ (if I
need), carefully, paying attention to speed, side effects, memory requirements,
and so on. With full testing, of course.

Hence, from "language for prototyping" I need next features:

1. I want to think about algorithm (!!!), and language must help me to do it.
It must take care on boring things like memory management, garbage collection,
strict type inference, my typos. It must provide easy-to-use packages for many
of my low-level needs. And so on.

2. goto 1:)

Python is realy very good for such demands. Except one: it force me to type
variable names carefully:) In other words, divert my attraction from algorithm,
to typing.

 AM> Even just focusing on
 AM> typos,
 AM> think of how many other typos you could have, besides the misspelling
 AM> of 'epsilon', that unit tests would catch trivially AND would be
 AM> caught in no other way whatsoever -- there might be a <= where you
 AM> meant a <, a 1.0 where you meant 10, a - where you meant a +, etc,
 AM> etc.
 AM> You can't live without unit tests.  And once you have unit tests, the
 AM> added value of declarations is tiny, and their cost remains.

Fine! Let interpreter never show us errors like division by zero, syntax
errors, and so on. If file not found, library don't need to say it. Just skip
it!!! Because every, even simple, test will find such bugs. Once you have unit
tests, the added value of <anything> is tiny, and their cost remains.


Or, maybe, we will ask interpreter to find and prevent as many errors as he

And, one more question: do you think code like this:

var S=0
var eps

for eps in xrange(10):

is very bad? Please explain your answer:)
 AM> Python has no declarations whatsoever.  If you prefer Visual Basic, I
 AM> strongly suggest you use Visual Basic, rather than pining for Visual
 AM> Basic features in Python.  If and when your programming practices ever
 AM> grow to include extensive unit-testing and other aspects of agile
 AM> programing, THEN you will be best advised to have a second look at
 AM> Python, and in such a case you will probably find Python's strengths,
 AM> including the lack of declarations, quite compelling.

Uh! And you! And you!... And you must never even come close to any languages
with variable declaration! Even to Visual Basic! :)

 AM> brain".  I find it's true: Python gets out of my way and let me solve
 AM> problems much faster, because it fits my brain, rather than changing
 AM> the way I think.

I'm agree with you.

 AM> If Python doesn't fit YOUR brain, for example because your brain is
 AM> ossified around a craving for the declaration of variables, then,
 AM> unless you're specifically studying a new language just for personal
 AM> growth purposes, I think you might well be better off with a language
 AM> that DOES, at least until and unless your brain changes by other
 AM> means.

Thank you for explanation of your opinion.

Alexander, zatv at

More information about the Python-list mailing list