[E-Lang] Immutable map operations

Dan Bornstein danfuzz@milk.com
Thu, 29 Mar 2001 08:44:47 -0800 (PST)


Tyler Close writes:
>Pursuant to my request for some code examples of "surprising
>operations", I think E should document the contract for the various
>operators by creating a test suite of programs that check the various
>axioms that an operator implementation must obey. Once such a test
>suite has been agreed on, it will be possible for a library designer
>to get a definitive and objective answer as to whether their use of
>the operator expansions is "good" or "bad" design. The prominent
>existence of this test suite in the E download should be enough to
>radically reduce the occurence of "wanton abuse of operator
>expansions" that language like C++ suffer from.

Let me second that. I know I've trotted it out here on the list before, but
I'll do so again, with this specific context. There's a great maxim that
comes out of the XP methodology:

    If it's not tested, then it doesn't work.

I also heard a great variant of it, originally in the domain of performance
tuning:

    If it's not measured, then it's out of control.

I'm not going to tout XP as a whole (it doesn't quite apply to open source
projects for the most part), but one thing I've really become a big fan of
lately is automated unit tests, where those tests are meant, in a very real
sense, to be an effective "executable spec" for the code (but not in the
usual way that term is applied).

What Tyler is basically suggesting is that there be a test suite for (in
Java terms) the interface associated with the operators, as opposed to a
particular implementation of them. With a convenient way to test for
conformance, it becomes harder for operator definitions to get out of
control (easier for them to stay in control).

The test suite could be written to work with any object, where, if the
object had the right interface, it'd be tested for conformance of it, and
if it didn't, it wouldn't. The suite would then be applicable to any
object. Then...

Radical suggestion: In at least one variant of "debug mode," bind the
":any" guard to something that runs the conformance test.

-dan