Loading…
C++Now 2021 has ended
Wednesday, May 5 • 11:30am - 1:00pm
Polymorphism À La Carte

Log in to save this to your schedule, view media, leave feedback and see who's attending!

Runtime Polymorphism is accomplished in Object Oriented languages in a variety of ways, each with their own trade-offs, a topic explored by Phil Nash at his CppCon 2020 talk, OO Considered Harmful. Several library authors have implemented runtime polymorphism via Type Erasure and, because Generic Programming is so powerful, these libraries rival the advantages or avoid the problems of the virtual dispatch mechanism intrinsic to the language. The work we present here is the result of having extended one of those frameworks, Zoo, to also support the mechanisms of other languages; despite this support happening in library-level code of an altogether different language, it can be substantially better than the intrinsics.

In particular, we will discuss, with examples, the advantages and disadvantages of these mechanisms:

1. Dynamic dispatch and late binding as in Smalltalk or Objective-C’s message passing
2. Rust Traits
3. Swift Protocols
4. JavaScript’s prototypal inheritance

and how close we have been able to capture their benefits and avoid their problems:

For example, we are able to model Objective-C’s message passing with superior performance to intrinsic v-table based “virtual dispatch”, allowing us to:

1. Achieve Value Semantics as opposed to limiting ourselves to just Reference Semantics.
2. Easily mock implementations to simplify testing using “method swizzling”
3. Very efficiently interop with normal Type-Erased containers that have the same polymorphic interfaces.

This presentation would hopefully help participants to apply the benefits of runtime polymorphism mechanisms from other languages in their C++ code.

Speakers
avatar for Eduardo Madrid

Eduardo Madrid

Eduardo has been working for many years on financial technologies, automated trading in particular, and other areas where performance challenges can be solved in C++. He contributes to open source projects and teaches advanced courses on Software Engineering with emphasis in Generic... Read More →


Wednesday May 5, 2021 11:30am - 1:00pm MDT
A