"no variable or argument declarations are necessary."

Michael ms at cerenity.org
Sun Oct 2 21:07:48 EDT 2005


James A. Donald wrote:
> On Sun, 02 Oct 2005 17:11:13 -0400, Jean-François Doyon
> James A. Donald:
>>  > Surely that means that if I misspell a variable name, my program will
>>  > mysteriously fail to work with no error message.
>> No, the error message will be pretty clear actually :)
> Now why, I wonder,  does this loop never end :-)
> egold = 0
> while egold < 10:
>    ego1d = egold+1

I know (hope! :-) that's a tongue-in-cheek question, however the answer as
to why that's not a problem is more to do with development habits rather
than language enforcement. (yes with bad habits that can and will happen)

Much python development is test-driven. Either formally using testing
frameworks (I'm partial to unittest, but others like other ones), or
informally using a combination of iterative development and the
interactive shell. Or a mix of the two.

With a formal test framework you would have noticed the bug above
almost instantly - because your test would never finish (Which would
presumably count as a failure for the test that exercises that code).

Whilst that might seem odd, what you're actually doing with type
declarations is saying "if names other than these are used, a bug
exists" and "certain operations on these names are valid". (as well
as a bunch of stuff that may or may not relate to memory allocation
etc)

With test driven development you are specifically testing the functionality
you want to exist *does* exist. TDD also provides a few tricks that can
help you get around writers block, and also catch bugs like above easily and
more importantly early.

Bruce Eckel (author of a fair few interesting C++ & Java books :-) has a
couple of interesting essays on this topic which I think also take this
idea a lot further than is probably suitable for here:

   * Strong Typing vs. Strong Testing:
     http://www.mindview.net/WebLog/log-0025
   * How to Argue about Typing
     http://www.mindview.net/WebLog/log-0052

For what it's worth, if you've not come across test driven development
before then I'd highly recommend Kent Beck's "Test Driven Development: By
Example". You'll either love it or hate it. IMO, it's invaluable though!
I suppose though the difference between static types based testing and
test driven development is that static types only really help you find
bugs (in terms of aiding development), whereas TDD actually helps you
write your code. (Hopefully with less bugs!)

Best Regards,


Michael.




More information about the Python-list mailing list