Published Sep 3, 2019

Episode 91: Kevlin Henney on C++

Kevlin Henney delves into the evolution, cultural impact, and complex features of C++, highlighting its historical significance and ongoing relevance in modern software development, while offering insights into template metaprogramming, idioms, and design patterns that define the language's power and complexity.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • Template Power

    Template metaprogramming in C++ offers powerful compile-time capabilities, allowing developers to optimize performance and memory usage. explains that templates enable the expression of complex ideas and relationships between types at compile time, which is a significant advantage over runtime reflection found in other languages 1. However, he notes that the language was not originally designed for this purpose, leading to some complexity and ingenuity required to make it work effectively 2.

    The template system is actually Turing complete. You can perform calculations in it, allowing you to do things at compile time that give you no runtime overhead.

    ---

    Despite its challenges, template metaprogramming has practical applications, such as injecting behavior into base classes, as seen in frameworks like Microsoft's ATL 3.

       

    Modern Idioms

    Contemporary idioms in C++ have evolved to simplify programming practices and enhance expressiveness. highlights that modern idioms focus on solving problems rather than just using language features, leading to more elegant and efficient code 4. The canonical class form, once a staple, is now seen as less essential, with newer idioms offering simpler ways to express relationships between operators and operations 5.

    The idiom landscape has definitely shifted. You see some surprisingly short and elegant pieces of code that years ago people would have expressed in ten times the size.

    ---

    This shift reflects a broader emphasis on value-based programming and encapsulation, reducing the need for manual memory management and outdated idioms 6.

       

    Design Patterns

    C++'s embrace of design patterns has significant implications for development and code maintenance. observes that the understanding of design patterns in the C++ community has plateaued, with many developers still adhering to the patterns outlined in the Gang of Four book 7. However, he notes that C++'s template facilities and operator overloading allow for the creation of domain-specific languages, offering a more flexible approach to design 8.

    The current growth in the idea of domain-specific languages, and also in particular embedded or internal domain-specific languages, where we create a sort of mini language within a language, actually goes back decades.

    ---

    This flexibility is exemplified by libraries like Boost, which leverage templates to express complex programming concepts without runtime overhead 2.

Related Episodes