[Cuis-dev] Generality number vs Double dispatch

Luciano Notarfrancesco luchiano at gmail.com
Fri Jan 1 21:20:37 PST 2021


IMO the double dispatch mechanism is pretty elegant, and I found it to work
well even after extending Smalltalk to cover much more of mathematics.

What I found more important is to make sure that every element has
“parent”, an algebraic structure it belongs to. Then, if I try to do ‘a *
b’ with a and b in two different rings A and B for example, the double
dispatch mechanism looks for a canonical ring homomorphism A -> B or B -> A
to convert one of the elements, and then resends the message with both
elements in the same ring, works perfectly.

Anyway, this is just implemented for convenience, in truth I don’t really
need it and I could just raise an exception when trying to multiply two
elements of different rings.

In the base image there’s a little annoyance because of the automatic
conversion of x/1 fractions to the integer x. I ended up creating a new
class Rational and avoiding Fraction in my code, but it’s not a big deal
for me, and the way Fractions work in the base image seems to be what most
people expect.

On Sat, 2 Jan 2021 at 12:52 AM, Ces VLC via Cuis-dev <cuis-dev at lists.cuis.st>
wrote:

> Hi again!
>
> Being completely new to Smalltalk, I learnt about the "double dispatch"
> technique yesterday, and my first reaction was that I felt quite
> disappointed, because everything I was learning in Smalltalk was clean,
> tidy, and efficient, ...until I read about double dispatching.
>
> Then I searched the Blue Book for double dispatching and found zero
> matches. Then I learnt Smalltalk-80 used "generality numbers" instead of
> double dispatching. With a bit more of searching, I found Cuis uses double
> dispatching because that change was done in Squeak by Ingalls time ago.
>
> When reading the "generality numbers" approach in the Blue Book, I don't
> feel disappointed at all: it looks to me like the clean and obvious
> solution to the problem (ie: binary operators should be legal for objects
> of the same class only, and trying to perform a binary on different classes
> should trigger an error... however, if for some reason you want Smalltalk
> to do the conversion for you, the generality number approach doesn't break
> tidiness and pure design).
>
> But I have a question, though: Did any of you have a long experience with
> Smalltalk-80 and found the generality number technique to be a limiting
> factor? I mean: Were your applications worse written (ie: with worse
> design) because of not having double dispatch?
>
> I'd like to check whether Smalltalk without double dispatching is worse
> than with it, or not.
>
> Thanks a lot,
>
> César
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20210102/5d1f9287/attachment.htm>


More information about the Cuis-dev mailing list