CppCast - Stop Teaching C (When Teaching C++)
Episode Date: October 14, 2015Rob and Jason are joined by Kate Gregory to talk about how we should be teaching C++ without the C. Kate Gregory has been using C++ since before Microsoft had a C++ compiler, and has been paid... to program since 1979. She loves C++ and believes that software should make our lives easier. That includes making the lives of developers easier! She'll stay up late arguing about deterministic destruction or how C++ these days is not the C++ you remember. Kate runs a small consulting firm in rural Ontario and provides mentoring and management consultant services, as well as writing code every week. She has spoken all over the world, written over a dozen books, and helped thousands of developers to be better at what they do. Kate is a Microsoft Regional Director, a Visual C++ MVP, an Imagine Cup judge and mentor, and an active contributor to StackOverflow and other StackExchange sites. She develops courses for Pluralsight, primarily on C++ and Visual Studio. In 2014 and 2015 she was Open Content Chair for CppCon, the largest C++ conference ever held, where she also delivered sessions. News Getting started with emscripten Range checks using a switch statement Debug Visualizers in Visual C++ 2015 Kate Gregory @gregcons Kate Gregory's Blog Kate Gregory on StackOverflow Kate Gregory's Pluralsight courses Kate Gregory's books on Amazon Links CppCon 2015: Kate Gregory "Stop Teaching C" CppCon 2015: Kate Gregory "Stop Teaching C" (Slides) CppCon 2014: James McNellis & Kate Gregory "Modernizing Legacy C++ Code" CppCon 2014: James McNellis & Kate Gregory "Making C++ Code Beautiful"
Transcript
Discussion (0)
This episode of CppCast is sponsored by JetBrains, maker of excellent C++ developer tools including
CLion, ReSharper for C++, and AppCode.
Start your free evaluation today at jetbrains.com slash cppcast dash cpp.
Episode 30 of CppCast with guest Kate Gregory recorded October 14th, 2015.
In this episode, we talk about how to get started with Emscripten.
Then we'll interview Microsoft Visual C++ MVP and Pluralsight author, Kate Gregory.
Kate will talk to us about how we only podcast for C++ developers by C++ developers.
I'm your host, Rob Irving, joined by my co-host, Jason Turner.
Jason, how are you doing today?
I'm alright, Rob. How are you doing?
Doing good. I'm just going to jump right into the feedback today. This is a short one. It comes from Iwan on Twitter, and he was replying to the last episode and said, excellent fix, gentlemen.
So I guess the last episode did turn out okay. I apologize again about the technical difficulties
we had, but hopefully the episode
turned out okay, and I didn't really hear any
negative feedback, just a
little bit of positive saying that the episode turned
out okay. Good. Yeah.
So we'd love to hear your thoughts about
the show. You can always email us at
feedback at cppcast.com, follow us on
Twitter on twitter.com slash cppcast,
and like us on Facebook at facebook.com
slash cppcast, and you can always review us on iTunes on twitter.com slash cppcast and like us on Facebook at facebook.com slash cppcast and you can
always review us on iTunes as well
and just so you know I did check my audio
recorder and everything should be fine this week
so
joining us today is Kate
Gregory Kate has been using C++
since before Microsoft had a C++
compiler and has been paid
to program since 1979
she loves C++ and believes that software should make our lives easier.
That includes making the lives of developers easier. She'll stay up late arguing
about deterministic destruction or how C++ these days is not the C++
you remember. Kate runs a small consulting firm in rural Ontario and
provides mentoring and management consultant services as well as writing code every week.
She has spoken all over the world,
written over a dozen books,
and helped thousands of developers be better at what they do.
Kate's a Microsoft Regional Director,
a Visual C++ MVP,
an Imagine Cup judge and mentor,
and an active contributor to Stack Overflow
and other Stack Exchange sites.
She develops courses for Pluralsight,
primarily on C++ and Visual Studio.
In 2014 and 2015,
she was Open Content Chair for CppCon, the largest C++ and Visual Studio. In 2014 and 2015, she was open content chair for
CppCon, the largest C++ conference ever held, where she also delivered sessions. Kate, welcome
to the show. Thank you. It's fantastic to be here. That's an amazing biography. It is.
So what language were you paid to program in in 1979?
That would be Fortran.
Okay.
Yeah.
And shortly after Fortran, there was PL1.
And some of my Fortran work was with cards.
Oh, wow.
I'm guessing you don't miss those days too much.
You got that right.
So, Kate, I just wanted to quickly say that I really wanted to thank you for some of your past podcast appearances because they're actually a big inspiration for me starting this show.
For those listeners who aren't aware, you've done a couple episodes on.NET Rocks, which, as its name implied, is a.NET primarily podcast.
They also delve into web development a bit.
And you've done a couple episodes with them where you talked about kind of the current state of C++ development. And after listening to those, they were some of my favorite episodes of that show.
And it kind of inspired me to create a podcast where we could have that sort of content every week.
So I really wanted to thank you for doing those episodes with.NET Rocks.
Well, thank you for running with the idea of having a C++ podcast, because it's true,
those episodes got a lot of downloads and a lot of listens. And then people would say,
how come there's no C++ podcast? And the answer always is, you know, because you didn't start it
yet. But most people, when you tell them that say, huh, okay, and wander away.
Well, I'm glad to finally be here,
and hopefully all those people who have listened to your.NET Rocks episodes
will eventually find CppCast.
Absolutely.
Yeah.
So I had a couple news items before we get into the interview.
This first one is getting started with Inscripten,
and this comes from a guy I know, actually,
on the visual or on
the Microsoft developer evangelist team, Dave Voiles, and he's not primarily C++ developer,
he's more of a web development JavaScript guy. And he's kind of approaching scripting from that
perspective, which I guess makes sense for getting your C++ code to run on the web.
And I just thought it was a really good
introduction to Inscripten that I haven't really seen before. Jason, do you have a chance to look
at this article? Just briefly, and it's, you know, there is definitely a learning curve to working
with Inscripten. So it's nice to see someone, you know, breaking it all down. Yeah, and it definitely
seems like there's even some install issues to get around,
so it's nice to have all those raised in front of you
so that you're aware of what you're getting into.
Kate, have you ever played with InScripten?
No, I first heard about it about a year ago before CppCon 2014,
and my first reaction was just like incredulity why why would you want to use c++
to write for the web and then I read the talk abstract and I was like oh of course it's always
about perf and about you know your investment in in code that you've already written and tested
and you know works and and the idea of porting that to javascript probably feels awful so then
I was prepared to concede like okay I can I can see why, you know, transpiling
to JavaScript rather than porting to JavaScript could be appealing. But everything I ever looked
at was written from the point of view of, you know, you know all about doing JavaScript and
whatever library is popular this week. And I'm going to write the instructions like that. And
since I'm not that person, I found them a challenge.
So what I like about this Dave Boyle blog entry is it's a little more step-by-step
and a little less assuming that you know all the steps.
Yeah, absolutely.
It's just a really good, well-drawn-out resource if you want to get started.
So, Jason, do you want to introduce this next item which actually comes from stack overflow yeah the next one like Rob said is
stack overflow question that someone had about using range
checks involving a switch statement and the question is
moderately interesting but the first answer to it
I feel like is just this
it's a great
what word
am I looking for?
Overview of modern C++
using modern techniques, making
sure that you're taking advantage of the
standard algorithms and everything else to
come up with some really clean
solutions and
it's interesting anyhow.
Yeah, definitely. Kateate i'm not sure if
you had anything to comment on with this one i i took a look at that question and uh the first
answer and it was sort of a sean moment um you know if you if you watched his seasoning talk
where he says this is obviously a rotate and the whole audience goes huh what um you know that
moment where someone says well well, it's pretty
obvious we can use upper bound for this, and you know, does it in a single line. And you have a
moment of going, what? And then, yeah, sure. Right. That is what upper bound can do for us. Absolutely.
I got it. I knew that. Totally. I was going to type that myself, but you did it first.
And we all have to start going through this that, you know, in I think, in type that myself, but you did it first. And we all have to start going through this.
I think in about five years, C++ developers who don't recognize opportunities for rotate and upper bound and really all of algorithm are going to be kind of in the dust compared to the people who spot something in the real world.
And just as you can say, that would be a good use of a linked list. We don't have that intuition about algorithms yet. And we need to. Yeah, yeah, that's, yes,
you did a much better job of articulating what I was trying to get across there with my mumbling.
But yeah, like upper bound, specifically, I have never found a use for it. I knew that it existed,
but I've never understood a good place to use it. Right. Like in an interview, if someone said to you, what does upper bound do? You'd give
the correct answer, but that's not what it's for, right?
Right.
And that to me is what's cool there. Here's something that it's for.
Very cool. So the next article comes from the Visual C++ blog, and it's about native visualizers,
which have been updated for C++ 2015.
And for those of you who aren't familiar with native visualizers,
they're just an XML format file that you can use
to tell the Visual C++ debugger how to display one of your classes
when you have the debugger up. So
instead of just showing you all the different member variables in there, you can format it to
be a nice, friendly, easily readable description of your object. And some of the new features
they've added is the ability to kind of change these on the fly while you're debugging, which
seems pretty impressive to me.
Kate, I think this kind of lends itself a little bit to what we're going to be talking
about with you today, how it's important that developers get more familiar with how to use
the debugger, right?
Yeah, and this feature's been here before, but it was hidden.
You had to give the file into this magic directory that, you know, you would never look in otherwise.
Most people didn't bother.
And that's a shame because being able to just hover over the variable or look down in your locals or watch window and get something you can understand.
When I'm doing things for.NET developers and I show them, you know, the data table visualizer, their eyes just go, oh, well, that works.
Now I can understand,
you know, what's happening in my program. And so surfacing these visualizers, you know,
they can be part of your project now. And so they can, that makes sense. I mean, you're writing a
class called employee. Where should the visualizers for employee be? The answer is in there with
employee, not squirreled away in this magic folder right right exactly um so i i really
think it's one of sort of the power techniques that you can teach someone to make them a better
debugger is to teach them how to write a visualizer for their for their type yeah absolutely and i love
this uh example they have in here with the gif where you can see them changing the visualizer
and showing how it updates immediately in the watch window. It's really pretty magical. Yeah, that's pretty freaky.
I'm looking forward to playing with that. Yeah. Okay, so let's start talking about your session
from CppCon this year, where you were talking about Stop Teaching C. I really love the title
of this talk. Do you want to give us a little bit of an overview? Well, sure.
The first thing I have to do is set context for it, right?
I wasn't at, you know, TechEd or a generic software development conference saying don't teach C anymore as though it was a language no one should use.
I was specifically at a C++ conference. So there's an implied first half of the sentence, which is when you are teaching C++.
Teach C++, right?
And I really wanted to expand on what is essentially one of my late night rants.
So, you know, put a glass of wine in my hand and I will probably start complaining about how on a five-day C++ course,
we don't do any C++ until you know day three and and the first couple days is almost indistinguishable from an intro to c course and um i think i'm beginning to have a big problem
with that i mean not just that it's wasteful which it is but i think it actually makes people
be worse c++ programmers than if you taught them C++ from the get-go.
Right. So who do you think you're aiming this talk at?
Obviously people who teach C++.
I'd like them to teach it more like I do.
But also sample writers.
If you're the guy on your team
who writes all the samples for your API
and you essentially write C samples, little console apps that are full of printf and square bracket arrays and things, then the brand new developer who uses your sample as a starting point thinks that's how it should be done.
Right.
And certain Microsoft teams are rather famous for this behavior.
Okay.
Windows.
It is true that some of the examples on Microsoft's website are horrific.
Yeah.
Yeah.
I look at them and I'm like, you did not write this in 1982 and then not touch it since.
That's not what's happening.
So why does it look like this?
Yeah.
And, you know, very often, too, that stuff, it clutters the place up so that you can't see what it is you're supposed to be demoing.
Like their excuse for why they do it will be, I don't want to make anything more important than my API call. Okay, you know,
that's fair. But then why do I have to know the printf format specifiers in order to understand
your demonstration of how to make this API call? Especially when I'm going to make this API call,
you know, from a Windows program, which will not be doing any output through the console at all,
whether it's printf or cout or whatever.
But you write me a console app, and then I have to know what %f2.7 means or something.
Since you mentioned printf, it does seem a lot of people want to defend it.
Oh, they do.
They really do.
And some of it, like I can't say anything about printf before someone's there
saying something mean about stream io and and it's not hard to say something mean about stream io
right like there's there's plenty to say mostly about perf but they got other things to go on
about as well and and it's like a kid getting in trouble and saying yeah but my little brother
you should see what he did downstairs.
Like, printf doesn't magically become better just because streams are slow.
Right.
And I'm not saying don't use printf.
I'm not even saying don't eventually teach people printf.
But I am saying I think it's insane to use printf on day one of intro to C++.
I concur with that.
You know, I think there are way better options, including my favorite, which is nothing.
So what would you suggest you're doing instead of printf?
I would first say use the debugger.
You know, I did start programming with cards, and I would take my cards to a room, and I would hand them to a human, and then later I would get a printout.
And my mother, she used to put cards on a van, and she would get her printout the next day.
And when you write those programs, you've got to print your output out.
I get that.
But I don't think most of us do that anymore. And so if you want to show somebody how after you use the plus plus operator, this guy
is one bigger than he used to be. Isn't the debugger a fantastic way to show that? Right?
Absolutely. And then and then you're not cluttering up the code with with output statements of any
flavor at all. And presto, you're also teaching the debugger because this is like, I have a number of pet peeves and one of them is like, chapter 10, debugging.
So I guess you're mostly working with other Visual Studio developers where the debugger
is really front and center. So that's kind of an easy sell, right?
If you're using a different tool where maybe it's a separate debugger, that's all the more reason to teach it.
Okay.
Interesting.
Because if you guys go on Stack Overflow, do you not sometimes wonder whether these people are aware that there are debuggers?
Sure.
You know, like there's this output that says, I don't understand.
I can't tell if it's going into the if or not.
And it's like, well, have you attached a debugger and followed control to see if it goes into the if or not? No. Right. It'd be a
lot better to just put your code on the internet and get all the rest of us to answer that question
for you. You know, I could understand if they had debugged in and they're like, I don't understand
why it's going into the if, but they don't actually know. Right. Well, let's go into maybe some of the other
specific items you brought up during your talk. Char stars.
Yeah. So, do you remember learning C++?
Like, whenever you were first exposed to it?
Yeah, I guess for me it was about, you know, almost a decade
ago in university.
What was the hardest part?
Yeah, I guess all the different functions to work with char stars.
For me, the hardest part was pointers.
Okay.
I was always a little unsure about,
should I be putting a star here?
Should I be putting an ampersand here?
Do I need to dereference that?
Or have I already?
Or whatever.
And when you do car star on day one,
you're doing pointers on day one.
And you lead the learner into mistakes.
Like, oh, yes, you tried to set up an array of characters to hold the word hello,
but you foolishly thought that you only needed
five characters to hold the word hello
because you forgot to allow for the null terminator.
That's not a day one conversation.
Right.
And throw away those
and use string from the standard library
and people just immediately know what it does. throw away those and use string from the standard library,
and people just immediately know what it does.
I have a talk that I do for C Sharp developers.
I show them a page of awful string manipulation,
and I found it in the wild, and it really, really is awful.
The guy writes nulls into the middle of his string so that STR functions will go just up to the null.
And then he puts them back um and i show them that code and they all you know make noises and pretend to throw up and that's fine and then i put up the next slide and they're all like yes
that's much better see that's c sharp and we all like it and i'm like no it's not actually c sharp
at all right it's c plus plus but it's using plus equals to do appends. Yeah, and equals equals
to compare and all the things that we intuitively think about strings doing. Everyone can read it.
Everybody likes it. And then they're very surprised when they find out it's C++.
And my experience with people who have no C++ experience at all is that they are perfectly happy with string manipulations using the standard string on day one, and they totally get it.
They don't question it at all.
Yeah, I have to say, I still don't understand how strcat and strcopy, I have to look those up if I'm going to use them.
Because I so rarely do. And it's like, is it source comma target
or is it target comma source because they're not all the same?
And then wait, what about the underscore S versions or the ones with
N's in them? And so
depending on the default settings of the compiler you're teaching with, they may get
a whole pile of security warnings that you're going to have to either pragma away
or put in the project settings.
Now you're teaching them really bad behavior, like, oh, we're going to write insecure code
because we don't have time to explain what would make it secure.
Yeah, the only people who should have to know all those different char star functions
would be the person writing the string library.
Exactly. Right. Exactly.
Right?
Exactly.
So, you know, before there was a standard library,
the first two classes I wrote were a string library and a date library
to wrap up the C stuff into classes and objects,
because that just seemed like an obvious, you know,
it's an object-oriented language.
Maybe we could consider having some objects.
So it also has to do with how people think.
You want them to think objectly,
then let them have some objects to work with.
So by giving them strings and by giving them vectors as well
instead of square bracket arrays,
they start, you know, thinking in a class and object way from day one.
And then you don't have to un-teach all the bad behaviors
that come in from using arrays to try to be a data structure.
Is there anything else you want to add about square bracket arrays?
That's the next point I had.
Well, again, they just lead you down that path of off-by-one errors.
They don't know their own length. So unless, you know, if you want to pass them around, you have to pass their length
around. If you get that wrong, it's a problem. They're, they feel really complicated and awkward.
And you're trying to explain to someone, you know, the power of functions and they can't get past,
why do I have to put this, you know, comma n in to tell it how long it is um you know
i i programmed in pl1 pl1 had arrays that knew their own size and had sensible operator overload
so you could say a equals b and it would do a deep copy um we've had the expectation of that
from our software for decades and when you you use vector, when you use string, you get that.
Right. Teaching people to write their own deep copies again on day one. I just think it's out
of place. And the whole talk is not about you should write C++ this way. It's about you should
teach C++ this way. So there's a sort of a tradition that says, well, that stuff's simpler.
So we're going to start with the simple stuff and then we'll put the complicated objects in.
And maybe if you had to write the objects, that might be true.
But they're in the library.
Right.
And they're super not complicated.
You just use them. So, what
skills do you think a C++ programmer
might be missing if they don't
get this initial C teaching?
Well, there is
the matter of reading the old code.
You know, it will be
in a different language. If they come into something
that's just a mess of STR whatevers
and maybe inserting
some nulls into the middle of long strings, something that's wh a mess of str whatever's and and maybe inserting some nulls into the middle of
long strings uh something that's whizzing through uh a collection a square bracket array with pointer
increments especially if they're in the middle you know so p plus plus is equal to something or
another um all of that yuck they won't be able to read that so they'll they'll need to be taught how to read that if that is part of their life.
And I know there are people for whom it is.
Other than that, what mostly happens is you free up about a day or two of teaching time.
So what kind of course would you recommend to them, though, if they do start off learning c++ and they later have to
go back and learn some of these other concepts should they go back and take a course on c
yeah i mean kenny's got great c courses at plural site you know take some of those absolutely
because it's not just about memorizing all the str functions it's also things like you know when i say
that i have an array called a and then
i do something to a i'm not doing it to the array i'm doing it to the address of the first element
of the array that has to be taught it's not obvious or intuitive at all i think it's somewhat
easier to learn later especially if you've now you know slowly worked your way around to pointers
the way i like to do pointers now is after references okay I know it sounds like I'm
I should be tested right but uh you can do with references pretty much everything except for the
null pointer that you can do with pointers so you can pass into a function by reference
you can get polymorphism through references All the sorts of stuff you'd like to demonstrate,
but the punctuation doesn't change.
So if I change the function from taking an int to taking an int ref,
I don't have to go through and edit the body.
And if it's an employee versus an employee ref, it's still all dots.
I don't have to go change them all to arrows.
And that lets people really focus on what's happening.
And then after you've done that,
you can issue this really strange sentence
where you can say,
pointers are basically like references,
except it's the exact opposite of how we were taught.
And then you can introduce the idea of the null pointer.
And of course, repointing,
because a pointer can point to A for a while
and then point to B, which a reference can't.
Right. So they have a purpose. There's a reason for them. And this actually makes them more acceptable. When I teach people pointers first, and then I try to teach them
references, they're sometimes kind of irritated. Like, why do I need that? Why couldn't you just
use a pointer? So I say, well, because you can do less with a reference, that's a feature,
they don't always buy it.
So for beginners, teaching them the more limited thing that you can't repoint and it can't be null,
and they get that, and that's great.
And then you teach them this extra thing that you can repoint and it can be null.
And oh, by the way, it's also what you get back when you allocate memory on the heap.
They see a reason for learning it, and they're prepared to learn it.
And then once they know pointers,
if you want to now get into car stars and square bracket arrays and whatnot,
they're many days further in their learning process
and I think they're happier to learn that.
It's just not good day one material.
It's not never material.
So you're kind of talking about this from the perspective of like
a five-day training session
or something and now you've um freed up as you said the first two days because you're not teaching
c what do you do with those extra two days well a lot of courses they spend five days and they
either never get to or they only briefly touch on const, exceptions, and templates.
So that's one thing we do.
But you can also get shorter.
I did with James McNellis a one-day intro to C++, a single day.
And we did a const and exceptions and templates in that course.
Wow.
And you followed this advice where you didn't go into any of the C teaching?
Yes, yeah.
And in fact, this is where I first did the references before pointers.
It was James's idea.
We were kind of going round and round in circles
trying to do something.
And he said, what if we did references first?
And I looked at him like he was crazy.
And then I went, I think we can.
And we did, and it totally worked.
And we got immediate feedback from people who said that it made more sense in that order.
Wow.
So now that's my go-to order for doing that.
So do you, you know, we talked about the standard algorithms at the beginning of this.
Do you teach the students standard algorithms and the lambdas and that kind of thing?
Yep, I do. standard algorithms and lambdas and that kind of thing yep i do um you know if you want to write a
raw loop to uh you know put a bunch of integers into an array and then go through and see whether
there's a three in there or how many threes there are or whatever if your focus on doing that is to
just demonstrate how a four loop works that's great but if your focus on doing that is that
you might want to know how many threes are in some collection of integers then you want to use standard count right so i'll show them count
and sort and find and then that sets you up if you just showed someone count that will tell you
how many threes are in a collection of integers well then why not show them count underscore if
which you can find out i don't know how many odd numbers are in the collection of integers.
And if you want to show them find, you can show them find if,
and sort with a different predicate and that kind of thing.
And lambdas just slide right in there.
And I used to teach lambdas like,
now we will do the lambda module,
and I would show them a lambda and explain it to them,
and show them another lambda and explain it to them.
And I don't know, people were probably trying to chew their feet off
in the back of the room and leave.
But now I just walk right into it and say,
you know, that third parameter to this function call
is what we call a Lambda.
And it's some code that you want to have run right there.
And people trust you.
They came there to learn from you.
So they believe you.
And after you've successfully counted the odd numbers or whatever,
then you can say, okay, now let's take a little bit of a sidebar
and talk about this syntax, because I get that it's kind of punctuation-y.
Let's talk about it, and then we go through the pieces of it.
There are a lot of...
And eventually, yeah, there is.
You know, and I have a slide in almost every talk which has the empty lambda.
Right.
I say like, okay, let's just get this over with.
Yes, this is a lambda.
I understand it is just six consecutive pieces of punctuation.
Ha, ha, ha, ha.
Okay, now moving on.
But the idea of controlling the capture,
being able to capture by value or capture by reference,
other languages that have lambdas don't have that.
You know, you get what you get and you don't get upset.
We're the ones who say, uh-uh-uh, I'm in charge here.
And it's my foot.
And if I want to, you know, capture by reference and then have that reference dangled
because whatever it was a reference to has gone away.
I'm the one who chose to do it that way.
And that power is why we're C++ programmers.
I've got to say, your approach reminds me a lot of how I personally learned Java.
And I was exposed to the Java standard library, and I'm like, you know, I'm never going to write any of my own code at all
if I don't have to.
I'm going to use this library of classes that already exist.
But for some reason, I didn't take the same approach
as I got, you know, I understood C++ more initially.
And it seems like just in general,
if you read comments and questions
that people have on the internet,
they feel like I'm writing in C++,
clearly I have to write everything from scratch on my own
instead of looking to the standard algorithms in the standard library. And
it might be because they all learned C++ by learning C first, like you're saying.
Well, and some of it has to do with an age thing. So when I started writing C++,
there wasn't a standard library. And there are a lot of us like that. We have a ton of experience.
And, you know, these are not hard things to write.
I need to iterate through this collection, testing against this condition, and when it matches, I'll break.
That's not really a very challenging day to write that loop.
So, meh, I write the loop.
And I don't necessarily think about the burden that I'm putting on the people who follow, who have to read my 10 lines and figure out what they do.
So I get in that habit and I'm tutting along.
I'm okay.
I'm fine.
And then other people start to join me and mentor with me and watch what I do.
And so golly, don't they do the same thing?
And it just becomes like a habit.
Why would I go and learn how to do it another way when I have found a way to do it,
even if the way I'm doing it maybe isn't as readable, or maybe isn't as high performing,
or has some other bad reason? I've already got it. It's comfy. It's familiar. It's my old shoes.
And so I really think we're going to have this kind of deliberate sea change where people start saying, you've got to stop rolling your own for things that have been available in the library,
you know, for decades, literally.
Right.
I'm pretty sure it's been 15 years that Scott Myers has been saying,
prefer the standard library algorithms to your own loops.
And I read that advice, like, like when effective C++ first came out.
But I didn't do it because you had to use function pointers.
Yeah.
That's a pain.
Yeah.
I mean, they're yucky, you know.
And especially back then, I was younger and less experienced,
so I was more intimidated by them. but they're still, they're hard to maintain. If you're lucky, the function's
in the same file. It usually isn't. If you're lucky, the name stays in sync with what it does,
but it usually doesn't. And especially before we had the sort of power that we have nowadays
in editors, you couldn't just easily find out what the body of that function did.
So until we had lambdas,
most of the standard library was just a closed door.
Lambdas come along and they open that door.
Because if you want to find all the odd numbers in a collection,
you call find at begin of the collection,
end of the collection,
and then
a lambda that just returns, you know, whatever it is, mod two is equal to zero or is greater than
zero, whatever it is you're trying to test for. And the person who's reading the code can see
you're testing that this is an odd number. And they don't have to go look at another file. So
you have much, much better expressivity. And we have that luxury in this last five years or so of talking about how much does my code express my intent?
How easy is it for people to see what I'm doing when they read my code?
I wanted to interrupt this discussion for just a moment to bring you a word from our sponsor, JetBrains.
ReSharper C++ makes Visual Studio a much better IDE for C++ developers.
It provides on-the-fly code analysis, quick fixes, powerful search and navigation, smart code completion, automated refactorings, a wide variety of code generation options, and a host of other features to help increase your everyday productivity.
Code refactorings for C++ help change your code safely, while context actions let you switch between alternative syntax
constructs and serve as shortcuts to code generation actions. With ReSharper C++,
you can instantly jump at any file, type, or type member in Solution. You can search for usages of
any code and get a clear view of all found usages with grouping and preview options. Visit jb.gg slash cppcast dash rcpp to learn more and download your free
30-day evaluation. And use the following coupon code to get a 20% discount for the ReSharper
C++ personal license. CppCast, JetBrains, CppTools. All right. So how was the talk received at CPPCon?
So before I gave it,
the title
consisted of a wonderful
way to cause, pretty much it felt
like the whole conference to come up to me and stick up for
PrintF.
Like,
more than once I was grabbed on the
escalator by someone who's like, hey,
I'm totally going to your talk.
But listen, Printef is fantastic because so that and my talk was Friday.
So I got a lot of that until I finally gave the talk.
During the talk, Twitter went mental, I think, because they thought I was just like saying C is awful and we shouldn't teach it to people anymore. But afterwards, I got a lot of comments from people who said things like,
either I learned that way from someone else, because that makes sense.
I didn't invent this.
That's just observing what worked for me.
And it's good and it does work and you're right.
Or, you know what, that's a good point.
I think I'm going to try that.
And I think the big motivator for people who are going to try that is the idea of being able to shoehorn more stuff in.
Like you feel guilty if you have, whether it's one, three, five days, no matter how long you have, you've got to leave something out.
Like when we did the one-day course, you know, we didn't do asynchronicity, right?
We didn't do futures and tasks and all that.
You've got to leave something out. If we can spit skip all that time on printf
format specifiers, and the STR functions and, and other things that you don't need the rest of your
life, then we can do a good job with const, we can cover our AII, we can maybe teach some of the
standard library. And maybe we can get into some kind of architectural advice to people as well and best practices.
Golly, maybe we could even cover testing.
It could happen.
So that, I think, is partly what makes people excited,
that they're like, oh, I can fit more stuff
into my existing course.
And that makes us happy.
I'd like to point out also,
by taking the approach that you are,
you're setting up C++ developers
to write code that is more
cache friendly, the compiler is better able to optimize, and is in general better, more
maintainable code. Absolutely. That's my number one motivation. I mean, like selfishly, the course
is more fun, and I get good reviews. But in the bigger picture is to actually make better C++ developers
who write better C++. And having them think objectively from the get-go, having them leverage
the standard library, these things will make better C++. Like you say, things like cache locality,
it starts to really matter now. Most people have got no idea how to do that themselves. So if the library can be counted on, you get
better code. Yeah. I went to your talk at CppCon. It was kind of a revelation to me. It made me
think, I want to try teaching C++ just to see how this goes for myself, too.
Well, find yourself a local victim. I taught my children c++ so oh really how'd that go
how old are the children uh well now they're 26 and 22 uh but the uh the younger one especially
um he wrote some code that's in um released production code so so at what age were they
when you're teaching c++ to them? I taught them programming
starting at around 12, 13 and then
C++ later I wasn't willing to do
C++ as a first language but that
was you know 10 years ago
since then
I think it can be a first language
and I had a conversation
with Bjarne about this and
he's got a book which is essentially
C++ as a first
programming language and i don't think you have to be him to do it i think anybody can do it
but you you sure are not teaching them printf on day one if they've never programmed
yeah my my son is a little uh too young for this now but i think in a couple of years i might try
to teach him using something like Cinder, I think
would be a good way to introduce someone to C++.
That'd be interesting.
Anything that you can get
a compelling UI quickly, I mean,
even if it's like,
geez, it might have been VB6
that I started my younger one on.
But there's a button and you click it and then a message box
comes up and says, woohoo, that tickled.
They think that's great.
And a console app is not the same.
It's definitely not as exciting.
Yeah.
And Cinder is nice because they can make explosions and robots and whatnot, you know, pretty quickly.
Right.
So you're really busy at Cpp Con this year, because you were also the
organizer for all the lightning talks, right? Yes. So how did that go this year? Oh, you know,
I was just blown away. Even after last year's experience, which was astonishing, I kind of
thought it was a one off, but it wasn't. People really, really want to give lightning talks,
hugely. And however many sessions that we make, really want to give lightning talks, hugely. And however many
sessions that we make available for people to give lightning talks in, they fill up. And I think some
of that is that people think that a lightning talk is easier than an hour-long prepared talk,
which it actually isn't. But that said, we we have a perfect record last year and this we have zero deaths
amongst lightning talk speakers so that's that's excellent i can't ask for better and most of them
that came down off that stage with the there's a grin that you see from someone who hasn't died
they've stood there and they've said something for 10 or 15 minutes and then there's been clapping
and then their heart is still beating and they smile a certain way
and it's like, oh, you're hooked now.
You're in the tribe.
You're going to speak.
And we had speakers this year
who were lightning talkers last year.
And that's fantastic.
How many lightning talk sessions were there?
I lost count personally.
I also lost count.
They were 8 a.m. I think there were three 8 a.m.s. There count. They were 8 a.m.
I think there were three 8 a.m.s.
There were three 8.30 p.m.s and a couple of lunches.
So is that eight?
There were a lot.
Hitley State?
Yeah.
Wow.
And there could have been more.
Like we were still getting requests when all the slots were full.
Oh, wow.
Yeah.
That's amazing. When I first did it last year, I seriously thought that I would be twisting the arms of five or six of my friends.
And I could, you know, cobble together something not awful by basically getting people to stand up and rant on whatever their favorite thing is.
Like, you know, let's get James McNellis to talk about whether const should be before or after the type.
You know, const int versus int const.
You know, you don't need to poke him very much to get that talk out of him. And I thought I would
have to do that sort of thing. But what happened was just this wave of interest came out of the
attendees and all of the talks were spontaneously suggested by attendees.
That's great. And all those talks will be made online along with all the other full sessions, right?
So they weren't all recorded.
The ones that were recorded will be online.
And even the ones that weren't recorded, the speakers have submitted their slide decks.
So you'll at least have their slides.
Yeah.
Very cool.
And by the way, CppCon has been dumping lots and lots of videos onto their YouTube channel.
Not everything is there yet. I actually looked to see if your talk was up yet their YouTube channel. Not everything is there yet.
I actually looked to see if your talk was up yet, Kate, and it's not there yet.
But there's a lot of content available.
There's a lot of content.
I looked yesterday.
I didn't get a chance to look this morning.
They're not certainly tweeting out links as they go.
But it clearly has started, yes.
And do you know what that means?
That means I have a to-do list now with about 50 hours worth of watching on it.
The nice thing about watching on YouTube
is you can increase the speed
so you can go faster
than the actual conference goers are able to.
Depending on the speaker.
Herb Sutter, I cannot speed up Herb.
In fact, I sometimes have to slow him down and say, whoa, do that again.
Oh, yeah, okay, I get that.
Because he was doing that again this year with the guidelines where he would toss some code up and say, well, clearly something that I needed a minute to see before it was clearly.
So I can't watch Herb fast.
But you're right.
There's a lot of folks at at 1.5 so you also mentioned to us that uh you
just got back from a big trip before uh cbb con is that right yes yes um that was my conversation
starter on my badge epic pacific trip um it's it's a completely non-technical thing but it's
such a thrill um we spent five weeks, and we went to 10 different Pacific islands
from Australia to Chile.
Yeah.
Wow.
Any favorite spots along the way?
At least 10.
Being just 10 feet from an octopus
that was moving and swimming and walking,
that was amazing.
Standing on the rim of a volcano, which was emitting lava and steam every five. That was amazing. Standing on the rim of a volcano,
which was emitting lava and steam every five minutes,
also amazing.
Wow.
Including when the lady in the dress came along
and said that we shouldn't stand right exactly there
because that's where the lava landed last week
and could stand a little more over that way.
And she's wearing like flip-flops and a cotton dress, you know.
Oh, wow.
She's the safety monitor.
Yeah, swimming through clouds of fish and over five-foot clams.
And, yeah, it was an astonishing trip that took two years to plan
and that I have not yet caught up on blogging about.
That is an epic trip.
Yeah.
So you mentioned the blog
where can people find that online
I believe it is called
transpacifictrip.wordpress.com
I actually tweet
links to it whenever I do an update
so probably the best bet is just follow me on twitter
as gregcons and then mixed in amongst
you know hey my C++ talk is up
or whatever other news I feel like
sharing on the C++ matter
there will suddenly be a link that says hey here's me on a volcano hey, my C++ talk is up or whatever other news I feel like sharing on the C++ matter,
there'll suddenly be a link that says, hey, here's me on a volcano.
That's awesome.
Well, is there anything else you wanted to go over today, Kate, before we let you go?
I think I just wanted to, again, thank you for doing the podcast,
but also ask you what you've seen in terms of C++ community because the response to CppCon, I think it surprised all of us. When we discovered last
year that it was the biggest C++ conference ever, you know, you kind of think like we had this glory
day once, and now we're living in the shadows of that. But in fact, this is kind of our glory day
right here. And I wonder if you're seeing the same thing
yourself in terms of c++ communities yeah we're seeing a lot of great engagement with the podcast
um it's you know growing every month we're getting more and more listeners uh we actually just got
the podcast put on the channel nine so hopefully that's going to attract even more uh c++ developers
from the microsoft community uh it's been a really great experience so far.
And I mentioned this last week,
but I was continually surprised
with how many people acknowledged the podcast at CVPCon.
So people are paying attention anyhow.
Yeah.
And when you go to a conference like that,
there's a lot of really young people there.
There's university students, undergraduates, you know, side by side with gray-haired ponytails.
And some of them are speakers, too.
Yes, exactly.
And that's fantastic because five or ten years ago, you know, I used to think that when I was done, I could turn off the lights, you know. But there's been this resurgence, and especially outside the Microsoft communities, that's just marvelous to behold.
Yeah, it's definitely a great time to be a C++ developer.
I think the GSL is extremely exciting.
You know, we all saw how popular that GitHub repository came.
So I think it's a good sign that people are definitely interested and engaged.
Yeah, yeah. it came so i think it's a good sign that people are definitely interested and engaged yeah yeah
well it's good to see it's gonna what if i do decide to just live on that pacific island and
not come back the language will be well looked after oh yeah it's in good hands well thank you
so much for your time today kate thank you for having me it's been great thank you
thanks so much for listening as we chat about c++ i'd love to hear what you think of the podcast Thank you for having me. It's been great. Thank you. I'd also appreciate if you can follow CppCast on Twitter and like CppCast on Facebook.
And of course, you can find all that info and the show notes on the podcast website at cppcast.com.
Theme music for this episode is provided by podcastthemes.com.