[Prev][Next][Index][Thread]

Re: Tim Sweeney on Programming Languages



Bruce Hoult <brucehoult@pobox.com> wrote:
>
> He doesn't really give many details of what he *does* want, other than the
> idea of "virtual classes".  This basically seems to be a convenience
> feature that if you have related classes A, B, and C, you can nest them
> inside another construct such that you can derive a set of new classes A',
> B' and C' in one step.
> 
> Given that there's no point in making a new class unless you're going to
> override some virtual functions, and that even today in C++ you don't
> actually have t mention the things that you *aren't* changing, I'm not too
> sure just what advantage Sweeney thinks you can get from this.  I
> certainly don't see anything that you couldn't do using Dylan macros.

I don't know if this is what Sweeney wants, but I've heard Cecil's
predicate classes called "virtual classes" before, and they are
actually pretty useful. Letting an object change its type based on its
runtime state essentially gives you the power that Haskell/ML
programmers have with pattern-matching on the alternative constructors
of an algebraic datatype. Only it's a little bit more extensible and
disciplined (read: less powerful) than pattern-matching is, imo.

For example, it could simplify the implementation of a streams
protocol, if an object could go from being a <stream> to an
<empty-stream> based on whether there are more more objects in the
stream. If NewtonScript (which I don't know) was prototype-based, then
implementing this would actually be pretty easy, since the parent of
an object is just another slot in an object. (I know you could do it
in Self, for example.)

Note that a similar mechanism is impossible in Dylan, and was likely
left out because it would often defeat attempts at eliminating
dynamic method dispatch -- though a substantial fraction of that
functionality (and hosage for the implementor) is available through
singleton types. You could build it in Common Lisp with the MOP and
CHANGE-CLASS, though.


Neel



References: