OO in Python? ^^

Chris Mellon arkanes at gmail.com
Sun Dec 11 09:24:42 EST 2005


On 12/11/05, Matthias Kaeppler <void at void.com> wrote:
> Brian Beck wrote:
> > def foo(self):
> >     raise NotImplementedError("Subclasses must implement foo")
>
> That's actually a good idea, though not as nice as a check at
> "compile-time" (jesus, I'm probably talking in C++ speech again, is
> there such a thing as compile-time in Python at all?!)
>
> Another thing which is really bugging me about this whole dynamically
> typing thing is that it seems very error prone to me:
>
> foo = "some string!"
>
> # ...
>
> if (something_fubar):
>     fo = "another string"
>
> Oops, the last 'o' slipped, now we have a different object and the
> interpreter will happily continue executing the flawed program.
>
> I really see issues with this, can anyone comment on this who has been
> working with Python more than just a day (like me)?

You are totally correct and this does cause errors. However, I'd like
you to take a few minutes and go back over all your C and C++ and Java
code and make note of how many lines of code and how many complicated
constructs you've used over the years to subvert the type system in
those languages. In my experience, and in many other peoples
experience, dynamic ducky typing saves far more work than it costs,
even when you factor in "typo bugs" which would be prevented by static
typing. Thats not even counting bugs in the extra code you've written
to work around the compiler. In fact, I'd say that a signifigant
portion of my time in writing C++ code is spent convincing the
compiler to do what I want, and not figuring out what I want. In
Python,  the opposite is true. My experience in that regard is pretty
typical - you'll find scores of stories on the web of C++ programmers
who switched to Python and breathed a sigh of relief.

All that said, there are automated checkers that can assist in
avoiding these kind of
bugs (as well as several others). Look into PyChecker and PyLint.

>
> Regards,
> Matthias
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list