© 2018 Strange Loop
Multiple dispatch, while by no means a new idea, has been taken further in Julia and its standard library than in any other non-research system. Organizing code around generic functions turns out to have significant implications for program design and structure. Rather than functions being closed operations whose behavior can be completely circumscribed, generic functions become the locus of abstract concepts with open, extensible implementations. Examples of such concepts are “+” for addition or “search” for finding elements, subsequences or patterns in collections. Being forced to factor APIs into abstract and extensible yet well-defined concepts-as-values is both a blessing and a curse. It’s hard to do, but once done, allows code to be written generically in terms of those concepts, and be automatically applicable to new types. Julia leverages this throughout its standard library, even for things as basic as promoting arguments of numeric operations to a common type. In a sense, multiple dispatch unifies functional programming and object-orientation: the ability to add new methods to functions gives the extensibility and openness of OO, yet this open-ended bundle of functionality is collected into a first-class value that can be used in higher-order programming.
Stefan Karpinski is one of the co-creators and core developers of the Julia language. He is an applied mathematician and data scientist by trade, having worked at Akamai, Citrix Online, and Etsy, but is currently a research scientist at MIT, focused on advancing Julia’s design, performance, scalability, documentation, and community.