Mother: Philosophy

Performance: Embracing Restrictions

[This section should really have examples. Maybe shape & intersect? Or equals?]

There are many language features that are slow in the general case, but with a few restrictions they can become really fast. For example, take Multi-Methods. That’s the name for choosing which version of an overloaded method to execute, based on the *runtime* type of the arguments. In the general case its slow, because you need to look at the types of the objects, figure out whether they can be converted to the types of the arguments, then pick the “most specific” of all the ones that fit, or raise an error if there’s more than one option.

But with a few restrictions, it becomes really fast. Java and C++ have fast dynamic dispatch based on the runtime type of the receiver. So if your function only has a receiver and no other arguments, dispatch is fast. Also, if there are only a few overloaded versions, and you know them at compile time, a couple instanceof checks are enough to send you on your way.

If you want fast dynamic dispatch on two arguments, a standard solution is the Visitor pattern. It has some limitations: All possible types for one argument need to be known at compile time; the types for the other argument need to implement a specific interface; and you need to generate some boilerplate code to hook it all together. But in many applications, those restrictions are no problem at all, and people happily use the Visitor pattern.

A core part of Mother’s philosophy is that, when needed, it can match the efficiency of Java. We’d prefer to do that without any restrictions or compiler hints, but when that’s not possible, we happily provide a way the user can specify the restrictions needed to make things fast.

Back to The Mother Programming Language.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s