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

Prototypes (was Re: kickoff)



On Tue, 2002-04-16 at 18:43, Avi Bryant wrote:
> Another wish I'd very much like to see fullfilled is keyword arguments.

This is pretty vital. :-)
 
> Also: may I ask why the type system was moved away from prototypes?

I participated in these discussions, and I'll try to summarize some of
the main points for you.  Jonathan may want to correct me here.  I only
contributed a small amount of code to Goo, and none of my statements
should be taken as anything more than personal opinions.

1. <foo> is typically not an instance of <foo>.

We found that--in most of our programs--that the prototype for class
<foo> typically had several missing fields.  These were filled in by
individual instances cloned from <foo>.  So (isa? <foo> <foo>) returned
true, but the "class" <foo> did not obey the contracts of an "instance"
of <foo>.

So a variable of type <foo> could hold either "subclasses" of <foo> or
"instances" of <foo>.  This had lots of weird consequences, and made
some of our code smell funny.

Now, you could work around this by making sure that the "class" <foo>
was also an "instance" of <foo>.  This is quite easy for <rectangle>
(just set all the co-ordinates to 0), but rather awkward for
<input-stream> (what input should it return?).

2. We wanted first-class types.

Goo, like Dylan, makes extensive use of types.  You can dispatch on
them, instantiate them, introspect them, and use them in variable
declarations.

Since types are a major, first-class abstraction in Goo, we wanted to
have such classes as <type>, <class>, etc.  But since you can't tell
classes from instances in a prototype-based language, these abstractions
never work right.

In short: "Dog" isn't a dog.  The furry thing wandering down the hall is
a dog.  "Dog" is a word, or a platonic category, or a biological
classification.  But none of these things have long floppy ears and a
tail.

Prototype-based languages are simple and easy to program.  And if you
have no more of a type model than SmallTalk, you probably don't even pay
any conceptual penalty.  But once you start having type declarations and
first-class types, prototypes blur a useful distinction.

So it's basically a matter of taste, and consistency with other parts of
the language design.  (Language design is not an especially orthogonal
problem--too many features interact in surprising ways.)

Cheers,
Eric