Inheritance and name clashes

Carl Banks pavlovevidence at gmail.com
Sun Oct 3 20:13:40 EDT 2010


On Oct 3, 3:04 pm, Rock <rocco.ro... at gmail.com> wrote:
> No, I was just working with a normal library
> class which was supposed to be derived. So that's what I did, but in
> the process I found myself needing to create an instance variable and
> it dawned on me: "how do I know I'm not clobbering something
> here???" ... I'd have to look at the docs, right? But I still wasn't
> sure ... so, then I thought "let's look at the source", and then I
> found out. But! It took me some time to make sure, and I was puzzled
> as well. I mean, what if I have no source to look at? What if the
> library I'm using doesn't realase the source, or what if I just can't
> get my hands on it for some reason or another?
>
> That was a big disappointment with Python for sure. Somehow PHP makes
> me feel a little safer, in that respect at least.

Name collisions are only one of several pitfalls that can happen when
you subclass a third-party clasa.  Another pitfall is uncertainly over
which methods a certain behavior is implemented, which is something
you can't determine from the interface alone, in any language I'm
aware of.  If you want to override such a behavior you have to look at
the class's implementation to find out how.  Point is, if Python
corrected this "defect", you still wouldn't be "safe" because there
are other dangers, which exist in other langauges, too.

Now, if a class is specifically designed to be subclassed by third-
party users, and it's not using name mangling or some other way to
avoid name collisions, then I would call it defective.


Carl Banks



More information about the Python-list mailing list