Programing Language: Polymorphism, Dispatch, and the Tale of Poly-Tinting

By Xah Lee. Date: . Last updated: .

in programing, there's this polymorphism, dispatch, multi-dispatch. These, are by-product of computer engineering. Are idiotic concepts.

what polymorphism is, is that it's a function f, such that what it does depends on number of arguments (aka arity) fed to the function, and or depends on the data types of the argument.

as a silly ad-hoc polymorphism example to illustrate:

function ff(a, b) {

    if (b == undefined) {
        return a+a;
    } else {
        if ((typeof a === "number") && (typeof b === "number")) {
            return a+b;
        } else {
            if ((typeof a === "string") && (typeof b === "string")) {
                return stringJoin(a,b);
            };
        };
    };
};

This is quite natural. But when it comes to implementation and language design, i assume due to difficulties, lots of issues comes up, and the language designer avoids it by creating by-products of work-around, spurious concepts, as did int long float double thing.

Now, in OOP, such as Java, for example, we have obj.f(a,b). There's a interesting thing going on. Namely, for some reason, in the implementation, what actually happens is that the function f has a implicit argument that is the object. Namely, it actually is like this: f(obj,a,b), and this is how most object oriented languages works. (and thus, such lang got mysterious spurious concept and keyword this.)

see

〔for full detail of this: OOP's Jargons and Complexities

So now, in Java, this calling a method of a object is in general sometimes called “dispatch”. Because, for perhaps implementation reasons, the language considered the call as calling a function named “f”, then identify the implicit first arg, then “dispatch” the call to the function that belongs to “obj”.

why the lang brought out “this” concept i never found out.

Now, there comes the idea of “multiple dispatch”, i first heard among Common Lisp idiots and they are fond of citing.

So, what's “multiple dispatch”?

apparently, in Common Lisp, since it's all parenthesis so it doesn't have the silly dot notation “obj.f”. [see OOP Dot Notation, Dot Before Data or After?] But, rather, the object is part of the function's argument, as in f(obj, a, b), or in lisp notation (f obj a b).

So, that is “multi-dispatch”. Because, the function f doesn't just “dispatch” to a fixed “obj” as in Java's obj.f(a,b), but rather, the function can behave differently depending on what is the first arg “obj”.

Now, can you see it's all very silly? From a non-idea becomes “polymorphism” and becomes “dispatch” and becomes “multi-dispatch”, all sounds so high-techy.

It is as if, in the land of object orientation, every time you drink a cup of water, you have to focus and distinguish whether the cup of water is in a tinted glass. Then, there's poly-color-tinted glass with red hue, and blue hue, then multi-hue…. What's the big deal? What about paper cup, plastic cup, tea cup, wine cup? Long time ago, in this country, their folks can conceive glass cups but are unable to make it, and when they finally figured out how, somehow it's always poly-tinted. Then, one day, a guy invented a color-tinted glass cup with a red hue, and that was big news, and somebody made a bluish one, and that's another advance of technology. Ever since, the culture of the country is to think of water always as a poly-tint. To not think of water by ways of the cup is, unnatural.

see also A Class of Computer Languages: Math Languages

If you have a question, put $5 at patreon and message me.