There are a few ways of approaching open extension, such as defining how operators are overload for every type. For Carbon, with its focus on performance, we are particularly interested in those that support static dispatch, to avoid the runtime overhead of dynamic dispatch. The three main options are:
- Open function overloading, where new overloads for a given name can be defined broadly, as is done in C++.
- Interfaces, as is done in Rust.
- Special method names, as are used in C++ and Python.
We would prefer to use a single mechanism, if possible, for simplicity.
Proposal is to use interfaces as the single open extension mechanism.
Details are in the added principle doc: docs/project/principles/static_open_extension.md.
This proposal is pursuing Carbon's goal of having code that is easy to read, understand, and write.
Early arguments for this approach were put forth in this document.