Presenters

Source

Relearning C++: Navigating the Modern Landscape with Fran Buontempo 🚀💡

Welcome to the GoTo Book Club! Today, we dive into the fascinating world of C++ with the brilliant Frances Buontempo, author of “Learn C++ by Example.” Hosted by Matt Godbolt, this conversation unpacks the complexities of modern C++ and Fran’s unique, engaging approach to teaching. If you’ve ever felt intimidated by C++ or lost track since the C++11 era, this post is for you!

The Evolving World of C++: A Journey of Relearning ✨

C++ has undergone tremendous changes in the last 15-20 years, making it a powerful but often daunting language. Fran’s book, originally titled “Learn C++ by Example,” might have been more aptly named “Relearn C++ by Example.” She specifically targets developers who once knew C++ but have since lost touch with its newer features, assuming a foundational understanding rather than starting from scratch.

Modern C++ has introduced incredible syntactic sugar and powerful features that simplify common tasks, yet these can be surprisingly hard to discover. Imagine trying to search for the spaceship operator (<=>) – punctuation isn’t exactly search-engine friendly! Fran’s book tackles these elusive, magic-like features head-on.

Key Modern C++ Features & Tools:

  • The Spaceship Operator (<=>): This fantastic addition provides comparison operators for your custom types for free, making it incredibly handy for standard containers like std::map.
  • Structure Binding: Unpack values from structures or pairs (like key-value pairs from a map lookup) directly into named variables, leading to much cleaner, more readable code.
  • Coroutines: A more advanced feature, coroutines allow you to pause and resume function execution, enabling sophisticated control flow. Fran bravely tackles this complex topic, even using them for seemingly “abusive” yet insightful examples to spark curiosity!
  • std::generator: A simplified version of coroutines, std::generator offers a Python-like yield mechanism for creating sequences or state machines with much neater code than traditional if/else ladders.
  • Essential Tools: Fran’s book introduces readers to Compiler Explorer (Matt Godbolt’s own creation!) and CppInsights, which help demystify what the compiler does under the hood with these new features.

Fran’s objective is clear: to highlight how modern C++ has simplified certain aspects, reducing the boilerplate code developers need to write. While C++ is still a vast language, these enhancements make it more approachable and efficient.

Fran’s Playful Approach to Learning & Teaching 🎲👨‍🏫

Fran believes in making learning an active, engaging experience. Her teaching philosophy centers on self-contained examples that allow learners to play with ideas and concepts directly. Her book features eight chapters, each built around a simple game like a “higher-lower card game” or a “slot machine.”

“I learned program computers by typing the source code onto my dad’s BBC machine,” Fran shares, recalling how she’d tweak game code to give herself “99 lives” in Pac-Man or Asteroids. This hands-on, playful experimentation ignited her passion for understanding what “all these weird instructions meant.”

Core Tenets of Fran’s Teaching Style:

  • Games for Engagement: Simple games provide a clear, fun context for applying C++ concepts without overwhelming the learner with a massive framework.
  • Learning by Arguing: Inspired by her father, a maths teacher, Fran finds that presenting surprising or counterintuitive examples can provoke arguments, leading to deeper understanding. As the XKCD comic suggests, sometimes posting the “wrong answer” is the quickest way to learn!
  • Practical, Self-Contained Demos: Fran’s acclaimed “X out of a Y bag” series of talks exemplifies this. She imagines a little dot trying to “code its way out of a paper bag,” using this simple visual metaphor to explore complex topics like machine learning algorithms and object-oriented programming.

This method stands in contrast to terse reference book examples, providing a much-needed bridge for people asking for “projects to play with” online.

The discussion also delves into specific modern C++ practices, like the use of the auto keyword. Fran presents the “almost always auto” style, acknowledging its contentious nature but emphasizing its prevalence.

The auto Keyword – Pros & Cons:

  • Pros: auto allows the compiler to infer the type, saving developers from writing out complicated types like std::vector<int>::iterator. This can lead to cleaner, more concise code.
  • Cons & Gotchas:
    • Initializer Lists: Using auto with an initializer list might not infer the type you intend.
    • Efficiency: In some cases (e.g., with lambdas), auto might prevent less efficient alternatives like std::function.
    • Copying: Incorrect auto usage can lead to unintended copies of large data structures, impacting performance.
    • L-values/R-values: Understanding auto often requires a grasp of concepts like L-values and R-values, std::move, and smart pointers (std::unique_ptr) to avoid subtle bugs.

Fran covers these nuances, providing just enough detail for readers to understand the implications without diving into dense type theory. She also touches on the complexities of Object-Oriented Programming (OOP) in C++, highlighting how modern features like move semantics and explicit copy control offer greater precision but also add to the cognitive load.

The Future of C++: Reflection and Meta Classes 🌐

Looking ahead, Matt and Fran discuss exciting future developments in C++, particularly C++26 and beyond. This includes the beginnings of static compile-time reflection, which will allow developers to query type information at compile time. Herb Sutter’s ideas for meta classes aim to leverage reflection for automatic boilerplate generation, promising to simplify complex patterns and reduce the chance of human error compared to AI-generated code.

The Author’s Journey: From Struggling Writer to Tech Icon ✍️📚

Fran’s path to becoming a published author is as inspiring as her teaching style. Despite struggling with reading and writing in school, she found herself drawn to the world of words, eventually editing the ACCU’s Overload magazine.

Her initial foray into book writing was a deeply personal one: attempting to finish a geometry book started by her late father. Realizing the immense challenge, she decided to write her own C++ book as a “warm-up.” Now, she’s even tackling an introductory C++ book for absolute beginners – a task she describes as “far too hard!” This journey underscores the power of perseverance and the importance of seeking help when needed.

Fran’s ability to make complex topics approachable, coupled with her infectious enthusiasm for C++ and teaching, makes her a true gem in the tech community. Her book, “Learn C++ by Example,” offers a valuable resource for anyone looking to refresh their C++ knowledge or simply explore modern features in a fun, practical way.

Connect with Fran! 📡

Want to learn more about Fran’s teaching approach or dive deeper into modern C++? You can find her blog, which offers overviews of her book’s chapters, and connect with her on LinkedIn and Blue Sky. Don’t miss the opportunity to check out her book and experience her unique way of unraveling the C++ mystery!

Appendix