[Tutor] A beginner having problems with inheritance

Danny Yoo dyoo at hashcollision.org
Wed Jul 9 20:17:35 CEST 2014


> My error was simply that I inadvertently used the same name for a method
> (function) in the derived class that I had already used in the parent class.
> The result was then a very obscure error because the wrong calculation was
> performed and later on an array was empty.
> Fortunately, thanks to you very generous tutors I have learned to read the
> error trace very carefully indeed.


Ah, yes, that one.  It's happened to me too.

It's one of the reasons why inheritance makes me nervous sometimes.
It's a problem that's fairly language-independent.

(If you'd like to know the details, the example that I was involved in
is described in the comments on:
https://github.com/bootstrapworld/js-numbers/pull/5.  Essentially, we
subclassed some base class, and wrote a method called BigNumber.exp()
to do exponentiation.  Unfortunately, we didn't realize that our
superclass already had defined an exp() method.  It ended up showing
up as a very strange, obscure error.  Same class of problem.)


Side note, Python does have a hack called "name mangling" that can be
used to try to avoid this problem:

    https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references


Good luck!


More information about the Tutor mailing list