Get the latest tech news

A polyglot's guide to multiple-dispatch (2016)


This is the first article in a series dedicated to multiple dispatch - an advanced abstraction technique available to programmers out-of-the-box in some languages, and implementable in others. This first post in the series presents the technique and explains the problem it intends to solve.

Showing how multiple dispatch is implemented in a language that doesn't support it natively is important, in my opinion, as it lets us understand the issue on a deeper level. This function may have a whole bunch of special cases inside for different combinations of shapes it knows how to do easily, before it resorts to some heavy-handed generic polygon intersection approach. One of the most notable experts to tackle the beast is Andrei Alexandrescu, who dedicated chapter 11 of "Modern C++ Design" to this problem, implementing all kinds of automated solutions based on heavy template metaprogramming.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Guide

Guide

Photo of Dispatch

Dispatch

Photo of polyglot

polyglot

Related news:

News photo

Buyer's Guide: Apple Watch SE 3, Series 11, or Ultra 3? 45+ Differences Compared

News photo

Buyer's Guide: iPhone 17, Air, Pro, or Pro Max? 40 Differences Compared

News photo

A PM's Guide to AI Agent Architecture