Re: "no variable or argument declarations are necessary."



On Mon, 03 Oct 2005 06:59:04 +0000, Antoon Pardon wrote:

> Well I'm a bit getting sick of those references to standard idioms.
> There are moments those standard idioms don't work, while the
> gist of the OP's remark still stands like:
>
> egold = 0:
> while egold < 10:
> if test():
> ego1d = egold + 1

for item in [x for x in xrange(10) if test()]:

But it isn't about the idioms. It is about the trade-offs. Python allows
you to do things that you can't do in other languages because you
have much more flexibility than is possible with languages that
require you to declare variables before using them. The cost is, some
tiny subset of possible errors will not be caught by the compiler. But
since the compiler can't catch all errors anyway, you need to test for
errors and not rely on the compiler. No compiler will catch this error:

x = 12.0 # feet
# three pages of code
y = 15.0 # metres
# three more pages of code
distance = x + y
if distance < 27:
fire_retro_rockets()

And lo, one multi-billion dollar Mars lander starts braking either too
early or too late. Result: a new crater on Mars, named after the NASA
employee who thought the compiler would catch errors.


Declared variables have considerable labour costs, and only marginal
gains. Since the steps you take to protect against other errors will also
protect against mistyping variables, declarations of variables is of
little practical benefit.


--
Steven.

.



Relevant Pages

  • Re: "no variable or argument declarations are necessary."
    ... >> Well I'm a bit getting sick of those references to standard idioms. ... > tiny subset of possible errors will not be caught by the compiler. ... > if distance < 27: ... one multi-billion dollar Mars lander starts braking either too ...
    (comp.lang.python)
  • Re: Variable declaration in middle of block?
    ... > I'm doing a simple compiler with C as a target language. ... > the possibility to declare variables anywhere in a block with scope to the ... void my_func ...
    (comp.lang.c)
  • Re: The Promise of Forth
    ... Declare variables, declare locals, let the compiler do the work of ... "That the simplicities will work together so that you'll wind up with ... "Fewer places for bugs to hide means faster debugging and the possibility ...
    (comp.lang.forth)
  • Re: The Promise of Forth
    ... Declare variables, declare locals, let the compiler do the work of ... "That the simplicities will work together so that you'll wind up with ... "Fewer places for bugs to hide means faster debugging and the possibility ...
    (comp.lang.forth)
  • Re: unprectable behaviour
    ... broken compiler. ... You coud, for example, use the debugger to see what values variables have just before things go wrong then write a program of the form: ... /* declare variables and initialise them to values the debugger gave you */ ... comp.lang.c posting guidelines and intro: ...
    (comp.lang.c)