Why Good Code is Relative
How the Environment Changes the Way We Write C++ Code
We all like to think that there is only one universal way to write good code which can be applied in all environments.
However, in reality, there is no such thing as universally good code. Just like every species in nature is adapted to its natural habitat, our C++ code also has to be adapted to the preconditions and the environment in which our code runs.
Drawing from the experience of over a decade of C++ programming in the embedded automotive domain, this talk is going to explain what this means in practice.
As one example, we'll start with a seemingly innocent constraint like "no heap allocations" and see how this leads us to a certain flavour of C++ that is best suited to work in such a domain.
On the way, we'll briefly revisit how dynamic polymorphism can be replaced with static polymorphism (CRTP) and learn how to extend CRTP to support an arbitrary number of inheritance levels to make it a full replacement for dynamic polymorphism .
Furthermore, we'll learn about deterministic re-computability and why this is something that one should aim for in self-driving / driver assistance functions. Imagine a problem that occurs every 100 or 1000 hours driven and for which you happen to have a recording. How can we guarantee that we can exactly reproduce this problem in a re-simulation? Answering this question will also have significant impacts on how to properly design SW for such a use-case.
Daniel Withopf has been working on solving real-world problems with C++ in robotics and related fields for over 20 years. He currently is a Software Engineer at the German car supplier Bosch where he wrote and maintains an object tracking framework for self-driving car projects. While doing that he discovered novel ways how to leverage C++'s type system to create linear algebra and tracking code that is more expressive, easier to understand and less likely to contain errors.