Sather Treasure

This is our yield from the Sather treasure hunt.

Code inheritance

Renaming, via the include statement, cannot resolve this problem. For example, if we rename B's secret to secret2, the program will print two 2's. But at least Sather warns us of the problem. In Python and Self, the program would happily print two 2's.

We think forwarding is a safer way to share code.

Efficiency vs. generality

Another argument for the "efficient" approach is that sometimes non-generality is part of the specification. We feel that such restrictions should be handled by a separate style-checker program, and not made part of the language. People are notoriously bad at anticipating future uses of their code.

Typecase : Contravariance

The typecase cannot be removed by overloading. If class FOO chose the signature is_eq(k : FOO) : BOOL, then it wouldn't be conforming to the $IS_EQ class type, and the compiler would report an error. This is also a problem in C++, but C++ does not have a typecase to remedy it.

Another response to this situation is covariant typing, as used in Eiffel. Under covariant typing, class FOO is allowed to use a more specific signature than specified by its type. However, this admits the possibility of a run-time type error.

In order to avoid run-time type errors, Sather has chosen the opposite rule: contravariant typing. Class FOO is allowed to use the same or more general signature than specified by its type. (C++ uses invariant typing: it requires exactly the same signature.)

(Aside: these five-dollar words are more expensive than the concepts they represent. We prefer "specialization" to "covariance" and "generalization" to "contravariance".)

Type-regress

Just as Self used a parent pointer to eliminate class-regress, we can use a "type" pointer to eliminate type-regress. Let "types" be ordinary objects which are pointed to by other objects. Types inherit from other types using normal object inheritance.

To check if an object O is a member of type T, we check if O type, or some parent of O type, is T.

We will see an explicit type system of this sort in the Life language.


PLE Home page
Last modified: Mon Feb 19 22:25:05 EST 1996