Should we make classes final by default? (was ACTSFW-82)
Original author Hadrien Benjamin Grasland @hgraslan.
Since C++11, classes can be marked as final, which prevents subclassing them. The feature originates from the Java world, and there have been many discussions in that community on whether that is a good thing. In a C++ context, I would argue that making classes final unless we want to subclass them is a good idea because:
- C++ classes must be explicitly designed for OOP. Any non-final class that does not have a virtual destructor a resource leak waiting to happen. Suppressing that footgun reduces the risk of accidentally introducing bugs in the future.
- Sealing class hierarchies with final can, in some cases, improve performance by helping optimizing compilers to remove virtual method indirection (devirtualization).
- A final keyword can be removed in a backwards-compatible fashion, whereas adding one after the fact breaks the code interface (if only a little).
- Encouraging people to avoid deep class hierarchies by making it even a little more effort to deepen one is a good thing as far as code maintainability is concerned.
This discussion generally applies to the core ACTS codebase as well. But since that's quite a large refactoring, I think attempting it first on the simpler and "private" test framework codebase in order to see how well that goes would be a wise move.