[MUD-Dev] Spoofs

Sean K sean at hoth.ffwd.cx
Wed Sep 26 12:33:00 CEST 2001


On Wed, 26 Sep 2001, Brian Hook wrote:
 
> The classic illustration is they inadvertently illustrate why C++
> is basically broken -- it ties the interface and implementation to
> each other tightly.  So when B inherits from A, you're never sure
> (from the outside) if it's inheriting the interface (for
> polymorphism) or the implementation (for specialization) or both.

C++ leaves most things up to the programmer.  Modern programming
style guidelines dictate that there should be a separation between
these but few people actually do it.  ie. there is a rule that
public functions should not be pure virtual, instead have them call
pure virtual private functions.  On a somewhat related note, Scott
Meyers wrote an article saying that moving as much implementation as
possible out of member functions into independent functions actually
increases object-orientation.  This is the beginning of the slide
towards generic programming.

> They go on to make an even more interesting assertion: extension
> by aggregation is generally preferable to extension by inheritance
> for the above reason.  They almost seem to actively discourage
> subclassing.

People are discovering that pure OO programming is not a panacea.
Performance considerations aside, designing and maintaining a large
inheritance heirarchy is quite difficult.  And there is not always a
logical mapping of a concept to an OO implementation.  I personally
subclass quite rarely.  Templates and the STL also make subclassing
both less neccessary and less useful than it had been.

> Hell, I'm using callbacks for a lot of stuff now instead of
> polymorphism because, in the end, it's actually quite a bit
> cleaner than subclassing everything just to minorly extend its
> behaviour.

I'm using function objects like crazy.  And in the case of callbacks
I use them as a mediator.  There's also the idea of policy-based
programming which is quite cool but that begins to open the door
towards needing partial template specialization which isn't commonly
available in compilers yet.

> Obj-C somewhat mirrors this philosophy (as a result of being an
> outgrowth of Smalltalk, which I'm just now coming around to
> realizing was WAY ahead of its time) via its delegate idiom and
> with its formal and informal protocol capabilities.  I just really
> dig on being able to ask any arbitrary object if it responds to a
> particular message without having to know its type a priori.

IMO this is Java's primary failing.  It's statically typed but
dynamically bound.  Smalltalk went the right way by making both
dynamic.

C++ templates provide a similar feature to Smalltalk's typing but at
compile time.  Between this and optional dynamic binding through
virtual functions, C++ can accomplish everything that Smalltalk can,
but it's not always as strightforward.

Sean

_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the mud-dev-archive mailing list