Loading…
Attending this event?
View analytic
Tuesday, September 25 • 15:50 - 16:20
yomm2 - Fast Orthogonal Open (Multi) Methods

Sign up or log in to save this to your schedule and see who's attending!

Have you ever felt your life would be simpler if you could just add virtual functions to a class hierarchy whenever you needed to (e.g., to persist an object or render it in JSON), but refrained because you did not own the classes and it would violate the principle of separation of concerns? Have you toiled on a Visitor class once again? Did you struggle to get double dispatch right because you needed to implement binary operations for polymorphic classes?
Open methods solve all these problems, while requiring you to write much less code -- and they deliver superior performance.

Open methods are virtual functions that are defined outside of a class. Given a method declaration and a set of specializations, the most specific version is selected depending on the dynamic type of one or more arguments. Open methods make it possible to add polymorphic behavior to existing hierarchies of classes, without needing to modify them. They provide a superior alternative to the Visitor pattern and a solution to the problem of cross-cutting concerns. Since more than one argument can participate in the selection of the specialization, open methods also solve the binary (or multiple) dispatch problem.

Circa 2007, Pirkelbauer, Stroustrup and Solodkyy wrote several papers about open multi-methods methods for C++, but the idea has failed to gain acceptance so far. My yomm2 library provides an implementation that is both fast (close to virtual functions), elegant and non intrusive.

yomm2 is available on GitHub (https://github.com/jll63/yomm2).

I wrote a series of articles on an earlier version of a library (yomm11), see https://www.codeproject.com/Articles/635264/Open-Multi-Methods-for-Cplusplus-Part-The-Case. Note, however, that yomm2 is a complete rewrite and improves significantly on the initial library. In particular, this version does not require changing existing classes to deliver good performance; methods are called via ordinary functions (overloading is now supported); specializations need not be in the method declaration's namespace.

Speakers
avatar for Jean-Louis Leroy

Jean-Louis Leroy

Senior Software Engineer, Bloomberg LP
I am the author of yomm2, a library that implements open multi-methods. See https://github.com/jll63/yomm2


Tuesday September 25, 2018 15:50 - 16:20
D

Attendees (29)