Home Bookclub Episodes Learn C++ by Exa...

Learn C++ by Example

Frances Buontempo • Matt Godbolt | Gotopia Bookclub Episode • February 2026

You need to be signed in to add a collection

Matt Godbolt interviews Frances Buontempo about "Learn C++ by Example," exploring practical teaching methods that make modern C++ features accessible through games and self-contained examples.

Share on:
linkedin facebook
Copied!

Transcript

Introduction

Matt Godbolt: Hello and welcome to another edition of the GOTO Book Club. Today, I'm joined by Frances Buontempo. Frances, why don't you introduce yourself?

Frances Buontempo: Hi, I'm Frances. I can't pronounce my surname properly, but no one can—it's Italian.

Matt Godbolt: Did I pronounce it wrong?

Frances Buontempo: It's close. I think it's Buontempo, but my family has always ignored it.

Matt Godbolt: It means like "good time," right? That's an interesting last name.

Frances Buontempo: The equivalent English surname might be Fairweather. Translating human languages is tricky. I'm not a linguist. I did maths and philosophy at university and then got into programming computers.

Matt Godbolt: We're talking to you today about your book. Tell us about it.

Frances Buontempo: I published a book with Manning. It came out last year. It's called "Learn C++ by Example." Between you and me, it might have been better being called "Relearn C++" because I've aimed at people who knew C++ but maybe lost track since C++11 or some of the newer features. I assume that you knew something about programming but don't know all the latest developments.

Matt Godbolt: Not like a course at university or teaching programming from the beginning?

Frances Buontempo: Exactly. I tried to keep it short—about 225 pages. I've only picked one or two salient bits that are common use cases where modern C++ has actually simplified things.

Why Modern C++ Needs a New Approach

Matt Godbolt: For those people watching who maybe haven't seen C++ in 15 or 20 years since they graduated, what's different? Why would you need a book to relearn it?

Frances Buontempo: There are quite a few little bits of helpful syntactic sugar, which are hard to look up. Things like the spaceship operator, which looks like less-than-equals-greater-than. The thing about punctuation is it's quite hard to search for.

Matt Godbolt: You can't search for it, right.

Frances Buontempo: I've introduced some tools including the famous Online Compiler Explorer—I think you've heard of it—and C++ Insights as well, which unpacks what things might mean. Things like the spaceship operator will give you comparison operators for free for types. That's handy if you want to use a standard map and you want some struct to be less than or greater than another.

Matt Godbolt: C++ lets you override all these things. It's complicated but there are 12 ways to do everything. This is a simplification that ultimately is the same as all of the other things or close to being the same as doing it all yourself.

Frances Buontempo: It will come out with the boilerplate that you would have written, but it will do the correct thing most of the time. There are nice little features like structured binding. You can unpack the first and second thing that you get back when you look things up in maps—you can see what the key and value are, give them names. These are nice little features that mean there's less code for you to stare at and scratch your head over. But being C++, they've brought in loads more bigger, complicated things like coroutines and ranges—more powerful things you can do that are quite hard to get the hang of. I've covered some simple things in the book and touched on one or two of the harder things like coroutines.

Matt Godbolt: That's impressive. Of all my experiences with writing C++, I've avoided coroutines. I've read about them and I looked at them and thought, "This sounds useful," but I haven't quite found the right spot for it in my own code yet. It's impressive to try and attack something as complicated as coroutines in a relatively small book. I mean, 200 pages is still a decent amount, but you cover a lot of things—you've got a broad set of topics.

Frances Buontempo: I try to find some simple things that make your life easier and then touch on one or two more complicated things. I'd come back from Meeting C++ in Berlin the other week.

Matt Godbolt: Which I believe you keynoted?

Frances Buontempo: Yeah, that was terrifying. I'm still getting over it. I had loads of questions afterwards. I kept it all quite high level. I was talking about learning and teaching and then delved into bits of machine learning and AI as well.

Matt Godbolt: Learning and teaching—humans learning from computers?

Frances Buontempo: What does learning mean? How do you know when you've learned something? How do you teach people things? Lots of big questions. I also did a quite short talk, which will be on YouTube at some point, going through about four or five examples of maybe abusing coroutines. Some of it was quite amusing. Some of it showed how you could create some magic things if you put your mind to it. It was like, "This is ridiculous. Don't do this in production code, but look what you can do."

Matt Godbolt: So much of what I've come to know as modern C++ started out as, "Hey, look, we can do this cool thing in the language." We never expected you to be able to do this, and ultimately that becomes the way to do things. It's good to explore the space.

Frances Buontempo: Things like template metaprogramming made everyone go "whoa" and hope they'd understood it. Now that we've got reflection working, goodness knows what we'll end up doing.

Matt Godbolt: There's a lot. For those who don't necessarily keep up with C++, it has changed an awful lot in even the last 15 or 16 years. It's useful to have a book that you can go to. As you say, if you have a little bit of experience of even C, you could probably pick up some of the C bits of it. It's useful to have an exposition of all the things you can do in C++—it's not as bad as it used to be.

Frances Buontempo: Some things are definitely easier and simpler. Like you can just output what's in a vector without having to understand what all the different types of iterators are. Some things are simpler.

Teaching Through Games and Examples

Matt Godbolt: Talking about teaching and learning, you have a particular style of teaching. I've noticed in the years I've bumped into you at conferences and reading your book. How would you best describe your approach to teaching?

Frances Buontempo: If you can come up with some self-contained examples that allow people to just hold in their head for a bit and play with the ideas, that's good. I tried in this book to come up with eight different chapters after the intro chapter that were little games you could play—like Hi-Lo card game or slot machine game. Then you can play with it. You can give yourself more lives, constrain things, see what happens if you do this or that. I learned to program computers by typing in the source code onto my dad's BBC machine because I wanted to beat my sister at Pac-Man, Asteroids, and all the rest. I found where the number of lives were in the code and changed it. Suddenly I've got 99 lives. That was my aim—to start looking up what all these instructions meant. Playing games engages some people better.

Matt Godbolt: To have, as you say, a self-contained example means you don't have to hold this huge framework in memory or library in your own head. You can just look at a couple of pages, three or four pages of code—maybe not even that much—and almost follow it on the paper and go, "Oh yeah, I see what that is." I can print it out and understand it, or I can type it in, as you say, or you can download it. I think you've got a GitHub repository. You don't actually have to type it in, although there's something to be said for the act of actually doing the typing—it might work it into your head a bit better for some people.

Frances Buontempo: It helps you remember when you do that. I said this at the keynote in Berlin—my dad was a maths teacher and ended up working at a teacher training college. He put a lot of time into thinking about how to teach people how to teach.

Matt Godbolt: The meta of teaching, teaching teachers.

Frances Buontempo: Exactly. One of his main points was, if you can get people to argue, that usually works. If you come up with something surprising or someone goes, "No, that can't be right, and I'll show you why," that's effective.

Matt Godbolt: Isn't there a law about this? You know, in order to find the right answer, you post the wrong answer and then everyone tells you what's right.

Frances Buontempo: That always works. Games give you that opportunity to go, "Oh, hang on, what happens if I jump into hyperspace or add some jokers to a deck of cards? And how do I even code that up?" It gives you possibilities. A lot of reference books are great and really well written, but because their focus is as a reference book, they come up with quite terse examples that usually have foos or widgets in them, which is good for looking things up. But the internet and Reddit are littered with people saying, "I want to learn more, suggest some projects for me to play with." Simple things like a Hi-Lo card game or something—that's a really good place to start.

Matt Godbolt: It's a fantastic way to be able to put something into context and see it being used in a way that is approachable and not covered with so much other complexity. Especially in a language like C++, which you're trying your best to show in a good light, but we've all as professional C++ programmers looked at code and thought, "Oh my gosh, this is a two-year project to understand what on earth is going on here." To be able to focus on something simple is valuable.

Frances Buontempo: Even with something like the spaceship operator, you start watching other things—complicated drawings and quite mathematical concepts really quickly, because C++ lets you do that if you want to.

Coroutines in C++

Matt Godbolt: That's a mixed blessing, right? Obviously you can phrase everything—ultimately you can throw away all that stuff. You can write C, which is barely above assembly language in my view. But it also scales all the way up to the very high-level meta ideas and approaches, concepts. Coroutines are kind of a funny one because they're almost more like a virtual machine than anything else. The idea that you can run two programs and have them switch back and forth inside your own program is interesting. If I remember rightly, the coroutines example you show is a generator, is that right?

Frances Buontempo: In the book I did a little example showing the generator, which was experimental in some compilers. You can do the equivalent of Python's yield. I subverted the "guess what comes next" example that I was playing with. You do like heads or tails and the machine guesses what you're going to predict based on the state of the last few things. I gratuitously wrapped it in a coroutine just to show you how to do this.

Matt Godbolt: Coroutines aren't necessarily a performance thing or to make a faster program. You've got to try and find an example that speaks to people rather than try a new example for people to wrap their heads around and introduce a completely new and somewhat alien concept—especially to more systems programming people. The concept of a high-level function where you can call this function and it can stop halfway through and give you a number—that kind of stuff makes sense when you do something practical with it.

Frances Buontempo: I tried to keep things simple. Now a lot more compilers are supporting standard generators fully. Nicolai Josuttis was talking in Berlin the other week about some examples. He came up with some really cool things where if you just yield results at certain points, you've kind of got a state machine, but then you aren't having to work around lots of ifs and elses to deal with the state changing. It ends up being much neater and you don't have all the edge cases dealt with using switches or ifs and elses. There are some ways it can make your code easier to reason about and read.

Matt Godbolt: The thing that I found difficult about coroutines is there's a lot of magic machinery that you have to boilerplate in a bit. It's relatively new and there's not a standard way yet. Generator is different because that kind of comes with the compiler and it looks like, as you say, Python.

Frances Buontempo: Writing a coroutine from scratch, you've got to find all the bits and pieces together. It's not straightforward, but loads of people have given talks about it. If you have to build one but you don't want the details, fine—just play with standard generator.

Matt Godbolt: That's valuable. We've all—I don't know of any C++ programmer seriously who doesn't dabble in Python on the side just to hold everything together. That's the glue language we've all adopted. You've probably used generator-style things with yield. You probably know the concept, and it's easy to write those things. It's very convenient sometimes, as you say. It builds a state machine for you.

“Almost Always Auto” and Modern C++ Style

Matt Godbolt: Talking about style things, I noticed in the book you go for what has become known as the "almost always auto" style. What are your thoughts about that? I think it's contentious among some people. Why did you go this way?

Frances Buontempo: I thought it was worth at least presenting it because quite a few people use it. There are obviously some edge cases where you get in trouble, like if you use an initializer list—that's what you've got and that might not be what you mean. Sometimes explicit is better than implicit. There are cases if you're using a lambda where you want to keep it as auto, otherwise it's going to end up in a standard function or something else, so it's less efficient. I find it much easier to say auto on both sides. It seems worth introducing. I don't think I've done auto everywhere through the book—sometimes I state the type of the thing I'm declaring. I think it's worth knowing about. Lots of people use it. There are obviously some gotchas because this is C++.

Matt Godbolt: Everything is a controversy, which is an unfortunate part of the territory a little bit.

Frances Buontempo: That's why we like learning C++. It can put some people off because they go, "Whoa, it's too big." If you can pick your way through it and just get the hang of the basics, that's really useful.

Matt Godbolt: C++ itself, you mean.

Frances Buontempo: Yeah, just get the hang of it. Even if you think it's hard, I've seen a lot of anecdotal evidence about people who, if they're a student or even a junior programmer, do a bit of C++, then they find other languages much easier.

Matt Godbolt: Because they've done it on hard mode once?

Frances Buontempo: More than once!

Matt Godbolt: If you've done C++, which despite the standard library and a lot of things, is kind of batteries-not-included—you're exposed to everything and the entire design space is open to you. You have to make your own decisions about which things make sense for you. Then you go to another opinionated language and it's like, "Well, okay, it's my way or the highway." If Guido van Rossum hasn't decided this is a good idea—I mean, there's a PEP now, but you know—then you don't get to do it. Maybe you'll get a little bit more of "I wish I could do this," but you just have to unfortunately pay the price to do it in C++. Maybe there's a bit of that.

Matt Godbolt: Auto is an interesting one. Sorry, I brought that up because it's something that I still argue with people about. For those not listening—for those who don't know what auto is—it's sort of like it lets you tell the compiler to work out what type goes here, a bit like "let" in many other languages or "var" in others. It just says, "Hey, it's a variable X," and it's still strongly typed because whatever you've got on the right-hand side, it infers. The thing is, if it infers it right, fantastic—it saves you writing "std::iterator of some complicated thing." But if it infers it wrong, then you might be copying a giant array every single time you're iterating. That's the kind of gotchas you were referring to, right?

Frances Buontempo: You need to watch out if you've got r-value references going on and all kinds of things.

Matt Godbolt: Do you talk about that kind of stuff in the book? I don't remember seeing it explicitly because that's one of the more theoretical sides of the language where you have your pr-values from your x-values.

Frances Buontempo: I didn't go into pr-values and x-values and all the rest of it, but I did talk about r-values and l-values and std::move—just enough to let you know that's kind of what it's doing, and here's more details if you want them.

Matt Godbolt: You don't want to put people off. You want to give them the tools that let them understand the program that you're writing. If you've used a unique pointer, you're going to have to learn about std::move if you want to push it and transfer it around. You need just enough to be able to say these things exist. If you want a treatise on category theory, you have to go look it up a little bit. I'm someone who has to look this up every single time—something that I should probably put on the side of a mug and have on my desk. But pragmatically, you know the patterns that make sense for you and your use cases.

Frances Buontempo: I did an introduction to classes. Compared to C++98, now you've got moves and you can enable or disable copies or default things. You have to consult a table about which ones are called.

Matt Godbolt: Oh my gosh.

Frances Buontempo: I have to look it up each time. Herb Sutter and others have been trying to play around with metaclasses to get things that actually generate some of the boilerplate for us automatically. I said this at my keynote the other week: please, we need more of this. AI generating things is often slightly wrong. If you're stuck, look it up or find a way to generate the code for you that's correct. There's a lot to remember in C++, and modern C++ is harder than it was, but you can be more precise than you used to be. Pros and cons, right?

Matt Godbolt: You're talking about the things that Herb's looking at for the future—C++26 and beyond. C++ comes up with a new standard every three years, and the latest greatest gets pushed into it. Coming in C++26 is the beginnings of reflection—static compile-time reflection where you can ask what this thing lets you do. Herb's ideas are then using that for generation, to be able to use the reflection and the power that it gives you to say, "Look, if I want a non-copyable class, I will say it is a non-copyable class by saying some magical annotation that can be replaced," and it's all written in C++ as well, which I think is a nice way of doing it. The obvious question from that is: will there be an update to the book for C++26?

Frances Buontempo: I'm bound to the publishers. Perhaps I should have a chat with them at some point. I am in the middle of writing another book at the moment.

Matt Godbolt: Oh my gosh, are you?

Frances Buontempo: The one I'm writing at the moment is an introduction to C++. It's for people who don't know it, which is far too hard to do. Why did I volunteer to do this? Oh my goodness.

Matt Godbolt: Wow. There's a lot. We sort of glossed over that by saying your current book assumes that you've got some working familiarity with it. Just the idea of explaining pointers and references from the ground up sounds challenging.

Frances Buontempo: Yes. The phrase "constant variable" caused some pause—like, "Oh, why am I doing this?" But yeah, we got there.

Matt Godbolt: It's like a live recording—it's an oxymoron or whatever, something that's self-contradicting in two words.

Teaching and Writing: A Family Tradition?

Matt Godbolt: You obviously write books—it's something you enjoy doing. I believe you're not the only person even in your own household that writes books.

Frances Buontempo: Yeah.

Matt Godbolt: Thinking about teaching and learning, it's something that just goes on around you and obviously from your family background as well. That seems like it's been part of you.

Frances Buontempo: I guess I've just ended up here. My dad wrote a book about maths once. That's probably how I ended up here. He'd written one book about maths years ago when I was like five years old. I thought, "Oh, my dad's written a book." My dad's famous! But it sold about 1,250 copies back in the '70s.

Matt Godbolt: That was a lot of money in the '70s, right?

Frances Buontempo: But he died a little while ago, over ten years ago, and he'd started writing a second book. I thought perhaps I ought to try and carry that on for him and actually get it published. But gosh, it was in three or four different places. I couldn't work out which was the most recent one. He'd got feedback on one thing, but they didn't return something else. I just looked at it and went, "This is going to take months and there are some bits he's not covered yet." It was about geometry. I've got a maths background, I've got a book on category theory—I can understand the ideas, I like the stuff—but there were some gaps in my knowledge. I thought, "I can't do this, this is ridiculous." By that point I'd given a few talks at some conferences. I thought, "You know what, perhaps I'll write my own book first and then see if I've got the bandwidth."

Matt Godbolt: So that's how you got into writing books—you were kind of resurrecting your dad's book?

Frances Buontempo: Yeah, kind of. Right now, I don't even know where the hard drive is where his stuff was. That's not happening. It was an accident. When I was at school, I was in the bottom class for reading and writing things. I was really good at maths, but I struggled to spell, struggled to speak properly. Both my kids struggle to pronounce things and I think it's from that direction. I can't hear the difference between "three" and "free"—it just sounds the same in my head because of how people talk. They're just the same. But I ended up editing the Overload magazine for ACCU, and that means I've got a review team because they correct my typos and things. I've learned that there are some things I can't do that I need help with, and that's okay. I just need to find the right kind of help. You can do things that you did not think you'd be able to do, which is amazing.

Matt Godbolt: That's fantastic. To be able to carry on the tradition for somebody who finds that thing quite difficult to do speaks to your character. You've got great ideas. One of the things I always think of when I think of you is your "X Out of a Y Bag" series of talks. Is there an example in the book? I think there is.

Frances Buontempo: Yes, there is.

Matt Godbolt: How did you get to that as a sort of teaching device?

Frances Buontempo: The book has an example of racing your way out of a paper bag. You set up some classes that move in different ways. One might just do one step at a time. One might take a random integer step. One might take floating-point steps so that you see the error accumulate. Then you just see who gets to the top of the screen first with an imaginary paper bag drawn around them.

Matt Godbolt: How did you get there?

Frances Buontempo: I was contracting at an investment bank in London years ago. I used to conduct interviews periodically with another colleague. We came out of an interview and my colleague said to me, "That guy couldn't even code his way out of a paper bag." I got slightly over-literal about some of the things I was going to say. I thought, "What do you mean? How would you even do that?" I stopped myself from saying all that, but it just wouldn't stop nagging at me. I thought, "Oh, I could do this, or I could do that." I got a few talks out of it. Once you've got a playground to play with things, it's quite a good way of playing around with a lot of machine learning algorithms and things. I realized how to make things leave and change. Here we are.

Matt Godbolt: This dovetails into your preferred way of giving people practical examples of things while being relatively simple and self-contained. You can draw a little bag on the screen and you can say, "Okay, we're going to teach the little character to get out of the bag." We give it a reward when it gets out the top of that. We do reinforcement learning or we do some other clever thing. That's just your approach to teaching—it's got to be something that you can hold in your head and simple enough to grasp.

Frances Buontempo: If you can come up with something that you can demo in one hour, you've got a talk for a conference for starters. Also, if you come up with a smaller example—sometimes it takes weeks to pare things down to the simplest possible example—then I can go for a walk and still have it in my head and think about it. Sometimes it's good to step away from the keyboard a bit to think about something. Otherwise you dig deep holes for yourself, which is the opposite of getting out of a paper bag, I think.

Matt Godbolt: That's fantastic. I love seeing the practical examples. The sillier the better—they're memorable, they stick in your head. The same with all of the examples in the book—you've got some fun little games in there that are almost worth typing in just to have a play around with them, even if you do know what you're doing. I don't think any of us really know what we're doing, honestly. Speaking as a professional C++ developer, I still struggle on. I find books like yours really valuable because it's a huge language. Just flicking through and going, "Oh, I'd forgotten that you can do that. I didn't realize you could construct in place." It goes into the back of your mind and it's another valuable thing to add to your day job.

Frances Buontempo: Just a few little clues and a little bit of surprising fun—that's what's important.

Matt Godbolt: Absolutely. Where can we find you online if people want to learn more about your approach to teaching?

Frances Buontempo: I've got a blog which has some overviews of the chapters. You can see what's in the book there.

Matt Godbolt: People can take a look on your blog and get an idea about what it is, and if they want to buy your book, I'm sure they can find it. I will post this in the description.

Frances Buontempo: I hang out on LinkedIn and Bluesky and various other places from time to time. I'll share some links that we can put up.

Matt Godbolt: Fantastic. Well, it has been an absolute pleasure chatting to you, Frances. I've really enjoyed it and I encourage folks to go and check out your book.Frances Buontempo: Thanks for chatting to me.

About the speakers

Frances Buontempo

Frances Buontempo ( author )

Consultant, Developer & Author of “Learn C++ by Example”

Matt Godbolt

Matt Godbolt ( featured )

Low-level Latency Geek