Coming from a background of hardcore number crunching programming (nuclear simulators and the type), I remember that one of my favorite mental hard ons for Smalltalk was the transcendental number system. Many modern "static system" compilers will also infer a good bit when noting mixed type math and put in implicit casts. But what has always even thrilled me more about ST is the ability to define new number systems and intermix them with the standard numeric types as appropriate.
In preparation to adding a new "numeric type o thingie" I got looking at how Squeak handles mixed math. To begin with, I didn't like it, it being like the OW coercion stuff, and I being more familiar with double dispatching as implemented in VW or ST\X. So I rewrote the basic arithmetic operations (+, - , / , *) to use double dispatching.
After having done this, I find myself at a crossroads of how to proceed. I've discovered that doing the double dispatching thing also has its drawbacks. Namely the number of methods required. For every new type of numeric thing one wants to add to the system, the number of required DD messages is 4(n^2). Whereas with using coercion, the number of type coercion messages is n^2. The drawback with coercion is that intermediate objects are created to complete the operation. With the simple mathematic types (Float, Integer) this is inevitable - sooner or later, you've got to get a float version of your integer. But with other "heavier" numeric types, these can be avoided by using DD. Take simple numbers combined with Points for example. To add a number to a point, you send asPoint to it, which creates a point to be soon thrown out. If you use DD though, you can avoid this creation by implementing something like:
sumFromInteger: anInteger ^anInteger + x @ (anInteger + y)
For points, the overhead isn't too bad, but as the new numeric types, get "heavier" you end up having to create special "intermediate" objects. VW SomeNumber is a good example of this.
I've completed the DD stuff, and was about ready to put it up at the archive, but then I stumbled upon this dilemma. Did the squeak team choose coercion over DD on purpose, or is this a historical hold over? Thoughts? More methods vs. more intermediate object creation?
-- Travis Griggs Key Technology tgriggs@keyww.com GO SMALLTALK - AND BEYOND!
squeak-dev@lists.squeakfoundation.org