declaration of variables?
Jp Calderone
exarkun at intarweb.us
Sat Feb 15 12:46:48 EST 2003
More information about the Python-list mailing list
Sat Feb 15 12:46:48 EST 2003
- Previous message (by thread): declaration of variables?
- Next message (by thread): declaration of variables?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Feb 15, 2003 at 06:05:09PM +0100, Andr? Jonsson wrote: > Being a Python-n00b, in the midst of this ?: discussion, it occurred to me > that Python does not require variables be delcared before use. > > Why is this so? Isn't it very helpful if the compiler complains rather > than having strange run-time results? > > Small example: > > if doStuff(42): > value=getNextValue() > else: > valeu=initialValue # <-- Note the spelling error. > > Surely, in an elightened language like Python it shouldn't be possible to > do this kind of error without the compiler complaining. > > The compiler.compileFile() function doesn't complain either, nor does > pychecker seem to. It's almost as if it was by design... is it? > "enlightened" language? Hrm. Dynamic, sure... OO, okay... functional, sometimes! But "enlightened"? Chances are, if you have this kind of error in your program, there will be an error, a NameError later on when you try to use "value" and it isn't bound. Compile time is almost always essentially the same as runtime, so you get the information at about the same time. Even better, if you have unit tests that cover this code path, you find out before you even run your actual program. Could the problem be avoided with variable declarations? Yep. Would I trade the flexibility of the current system for a small improvement in compile-time checking of my code? Nah, I don't think so. Jp > > /Andr? > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://catandgirl.com/view.cgi?44 -- up 6 days, 22:28, 4 users, load average: 0.40, 0.28, 0.13 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20030215/57de3332/attachment.sig>
- Previous message (by thread): declaration of variables?
- Next message (by thread): declaration of variables?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list