Evils of inheritance

tl;dr Yan Cui’s picture is worth a thousand words…

image

Programmers complain about context switching all the time, yet those same (some otherwise very good coders) end up going architectural-zilla, impose this on the code base and doom their future selfs and others to code that is difficult to reason about without a couple dozen tabs open across split windows.

That stuff is even a pain to step through in a debugger. You step in to something, and then are actually surprised when it opens up yet another tab on a file you had not even compiled in to your own mental picture.

If you cannot tell what something does by just reading the source file then friends, you have already lost. That strategic abstraction layer laid down has hurt you tactically. You may as well try and navigate London’s one way system in a car with a tourist map that does include which travel direction is valid and does not have all the street names. Driving around in circles while the people you are with are wondering why there is no progress being made.

Inheritance needs to be kept shallow and used sparingly. Mix-ins and other trendy forms sparingly too.  The funny thing is how the use of inheritance tends seems to naturally snowball. Then when the snow ball gets big enough you have an avalanche, causing things with “manager”, “supervisor” and “factory” in their names to spring in to existence.  All with hierarchies of their own. 

Perhaps inheritance is like a mogwai… a few rules that are easy to slip up on then before you know it… gremlins.