[MUD-Dev] Object Models

Miroslav Silovic silovic at zesoi.fer.hr
Tue Nov 28 15:34:10 CET 2000


"John Buehler" <johnbue at msn.com> writes:

> Some comments on your example:
> 
> 1. You have an error handling case where an object cannot be sharpened.
> This is an example where strict contracts and strong typing prevent the
> possibility of that happening.  A component that cannot be sharpened can't
> even represent itself to the sharpener.  The sharpen method requires that
> the component passed to it be an 'edge' component.  This would be checked at
> compile time, not runtime.  This is one reason why weakly typed languages
> are a pain in the backside.  Error handling was called "One of the four
> unsolved problems in software engineering" by one of our consultant types.
> I forget what the other three are  ;)

The question is whether you -can- design this in a way that allows for
static checking. Well... the sharpen, on the UI level, can affect any
object in the matchable environment. So you must query the object for
a reference to Edge object (if it has any). The problem happens when
the object may lose an edge at runtime (like, for instance, when your
knife breaks). Eventually you end up with an error handling case (edge
reference is non-NULL) either on the caller side or on the
implementation side. Note, you must never, NEVER, use preconditions
for runtime error checking (because the application should be
compilable without them), so eventually you either get something like
(the language is TOM, FYI):

[[object extractEdge] sharpen]

that may throw an exception or

Edge edge = [object extractEdge];
if (edge != nil)
   [edge sharpen];

The latter is a bad design because it forces checks that are VERY easy
to omit. So you do end up with error handling.

As a sidenote, most languages you call weakly-typed are actually
dynamically-typed. They're perfectly capable of trapping pretty much
any problem, provided you have a good test suite - which you need
anyway. Compile-time typechecking does so little for me that I'd happy
to give it up for the advantages of the dynamic typing.

--
How to eff the ineffable?
_______________________________________________
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