C++, Small Children, and Razor Blades [was SubTyping]

Jonathan S. Shapiro shap@eros-os.org
Wed, 16 Aug 2000 09:40:45 -0400


> To rephrase in what hopefully comes across as an
> entertainingly provocative style: "subtyping, including
> subtyping that adds authority, is part of how a few
> expert designers occasionally make nice abstractions,
> but most programmers typically achieve large balls
> of mud with incoherent interfaces and contracts."

Sixteen years ago, Roger Faulkner and I (in succession) were the lead
architects on the first commercial product that was written in C++ anywhere.
It was the UNIX Debugger built at AT&T. One of the folks on the project,
Mike Bianchi, was seriously in love with reusable code, and was determined
to organize everything possible as reusable libraries. C++ was being touted
as a reusability tool, and the intersection of these objectives was
predictable: we spent a large amount of time thinking about class reuse.

By far the hardest part of reuse and the greatest amount of our time went
into understanding how to support subclassing while preserving the integrity
of the existing object hierarchy -- what internal state needed to be
exposed, even though we didn't really want it messed with? What should not
be exposed? In which cases should we intentionally *avoid* exposing
something needed to subclass in a particular way because we knew that going
that way was a recipe for disaster elsewhere in the design space?

Somewhere in all of this, I disctinctly remember Roger letting out with the
assertion that letting ordinary developers use C++ was morally equivalent to
encouraging small children to play with razor blades.

My own thought on this subject is that designing for subclass reuse is
damned hard. The problem lies less in the language (though that can
certainly get in the way) than in the fact that you cannot anticipate the
requirements of the final user, and must instead arbitrage in the
requirements space for the entire design space. This requires a degree of
experience, insight, and occasional mystical awareness that is far beyond
what most programmers can bring to bear.

My book "A C++ Toolkit" tried to teach some of these skills. In hindsight,
the book was useful but I believe that it failed. I underestimated the level
of skill required for success by a good sigma, and maybe by two.


shap