TerseMan

Dan Ingalls DanI at wdi.disney.com
Thu Jul 2 19:17:29 UTC 1998


This is a in response to a message several weeks back that I set aside at that time.

Steve Dekorte <steve at inquisit.com> wrote...
>Communicating the benefit of objects may be easier by showing its value for
>high level objects first and letting people see the beauty of extending that downward
>than to try to convince people straight out that "+" should be a dynamicly bound
>message.

Maybe so, but I have never failed to get an "Ah-ha" out of the factorial part of my Squeak demo.  It's a bottom-up approach that seems to work well for people who are competent in some other programming language and wondering what Smalltalk is all about.  Here's how it goes...

First I show the code for Integer factorial, and explain how it works in terms of sending messages, and run it for 6 factorial, which anyone can understand.

Then I run 100 factorial, which is always fun.  We joke about whether it's correct or not, so I print
	100 factorial // 99 factorial
and we joke again about how it probably is correct, after all.  Moreover, it's clear by now that Squeak is doing serious arithmetic (ie division) on monster numbers, quickly and correctly.

THEN I go back to factorial and explain how the fact that the code is messages means that it will work for any kind of numbers, so long as they support those messages.  That's how it continues to work when the results get to be too big for normal integers.  If someone isn't getting it, then I show them max: in Magnitude and point out that this one tiny proceedure is constantly servicing Integers, Floats, LargeIntegers, Fractions, Times and Dates (show the hierarchy).  This is the power of polymorphism.

Finally I talk about how Squeak defines a virtual machine in which this metaphor of message sending IS the actual instruction set.  At that point I show the compiled bytecodes of factorial [that's why we bother to have show-bytcodes in a menu], responsible for the foregoing numeric pyrotechnics.  It never fails to blow people's minds that you can have this kind of power encoded in 21 (count 'em) bytes.  (max:, by the way, is 7 bytes).

	- Dan





More information about the Squeak-dev mailing list