Expressing Implementation Sameness and Similarity - Polymorphism in Modern C++ - Daisy Hollman

Discover the power of expressing implementation sameness and similarity in modern C++ through class templates, customization points, and other techniques, and learn how this approach can improve code reuse, maintainability, and understanding.

Key takeaways
  • Polymorphism in modern C++ is about expressing sameness and similarity of code, not just repetition of the same words.
  • Implementation sameness is crucial, as it allows reuse of code and reduces cognitive load.
  • The way to express sameness is through class templates, which are incredibly powerful and don’t cost anything.
  • Customization points, like CRTP, allow for a deeper level of sameness, but also require more knowledge and understanding of the code.
  • Using class templates to express sameness can help to reduce code coupling.
  • There are cases where implementation sameness can lead to poor design choices, such as the “mixins” pattern.
  • C++23’s deducing default implementation can help to alleviate some of these issues and make code more maintainable.
  • Interface sameness is also important, but it’s more about expressing the same abstract concept in different ways, rather than identical code.
  • Human perception and understanding of code are more important than the exact words used to express the code.
  • Code assistance tools can be useful in helping to write better code.
  • The concept of “cognitive load” is key, as it refers to the mental effort required to understand and maintain code.
  • repeal of concept can lead to poor design choices.
  • Adl (Argument Dependent Lookup) can be a powerful tool, but also risks increasing code complexity.
  • Being able to express sameness and similarity of code can make it easier to understand and maintain code.
  • The way we think about and express code is evolving, and C++23’s changes to the language reflect this.
  • It’s not just about writing the same code, but about expressing the intention and meaning behind the code.
  • The speaker uses the term “name forwarding” to refer to the process of taking the name of something (like a function or type) and reusing it in a different context.
  • The speaker believes that IF you’re writing code that looks similar to someone else’s, it’s likely because they’re expressing the same concept, rather than just copying.