CppCast - Postmodern C++ Revisited
Episode Date: April 23, 2020Rob and Jason are joined by Tony Van Eerd. They first discuss some conference news, including Microsoft's upcoming Pure Virtual C++ Conference. Then Tony Van Eerd joins them to discuss his Postmodern ...C++ talk, and some of his work on the C++ standards committee. News Sign up for Pure Virtual C++ Conference ModernCppStarter Announcing Meeting C++ 2020! Links Tony van Eerd: Postmodern C++ p1085R0 Should Span be Regular? Sponsors PVS-Studio. Write #cppcast in the message field on the download page and get one month license Read the article "Zero, one, two, Freddy's coming for you" about a typical pattern of typos related to the usage of numbers 0, 1, 2 Use code JetBrainsForCppCast during checkout at JetBrains.com for a 25% discount
Transcript
Discussion (0)
Episode 244 of CppCast with guest Tony Van Uert recorded April 22, 2020. Thank you. Use the coupon code JETBRAINS for CppCast during checkout at JetBrains.com to take advantage of this deal.
In this episode, we discuss some conference news.
Then we talk to Tony Van Eerd.
Tony talks to us about his updated post 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 doing all right. Rob, how are you doing?
Doing okay. Getting by. Do you have any news you wanted to share?
No, I don't think so. Nothing at the moment.
Weather's nice here, though, so that's at least something.
That's good, because you had snow a week ago, didn't you?
Yeah, it's been snowing every other week for a few weeks.
Sorry, not every other week, every Friday for a few weeks,
and sunny the other times.
But it's much nicer right now.
Did you move to Canada?
No, this is normal Colorado weather for us in the spring.
We don't know if it's going to be rain or snow any time between March and May, basically.
Right, Canada, you said, yes.
Yeah, basically, yes.
Okay, well, at the top of our episode,
I threw in a piece of feedback.
We got this comment on the website
for the episode from two weeks ago
with John Turner, your cousin,
saying from Bob McNaughton,
Rob, you didn't ask the question
that I think was on the mind of many parents
of young children when the Turners were reminiscing
about their childhood.
What were their influences?
Was there a teacher or family member in particular
who was a mentor to them?
What did the person do that encouraged
the extraordinary curiosity and creativity
of this remarkable pair? Maybe Jason could fill in the answer on a later episode so uh yeah you
got an answer you want me to fill in that answer now rob yeah so i did chat with john about this
um a little bit and i guess i should i feel like i should clarify this yes he does generally go by
jonathan professionally but you know i've been a family member of his for my entire life, so I just call him John.
He and I, as far as we can reconstruct the history, basically, his dad thought that having
a TI-99 was a good idea.
He bought one and told my dad about it.
My dad then bought one.
They are brothers.
That's the family relationship there and both of then
our older brothers who are approximately the same age played around on it and did artistic things
with it because they are both more artistic than they are programmers and john and i were both
influenced by that played around a little bit on it. And then I got excited about like typing in
the basic programs that would be in the back of magazines back in the day. And John told me he
tried doing the same thing when I told him that I was doing it. But he got frustrated with typing
in those basic programs. So he didn't really program for several years, until he decided
sometime in like middle school that he was interested in things again and he had moved on to like compiled languages he's like in pascal he's playing with assembly
and i'm basically still just playing with basic and q basic and whatever for gw basic for all
those like middle school high school years until we were hanging out again right before college
started and he taught me assembly language and we learned
some c and c++ together and that kind of thing so it was just the way we figure it's it was
having families that had the i guess means and interest in investing what was a lot of money
at the time to have a family computer and then having uh influence from each other basically and sharing
ideas back and forth over the years it's very cool i do wonder if you know younger generations
are not gonna have experiences like that at all because you know we have an ipad and computers
in the house but you're not programming on that kids are playing roblox and minecraft and stuff
like that all the time.
That's what mine are.
Minecraft is kind of like programming, right?
It can be, yeah.
And you can do more with it,
I think, in some versions of Minecraft.
Yeah.
But yeah, you don't boot up into a basic environment
and basically have to do some kind of programming
to load a game.
I mean, effectively, that's what you're doing.
That's not the same, no.
Okay, well, we'd love to hear your thoughts about the show.
You can always reach out to us on Facebook, Twitter,
or email us at feedback at cbcast.com.
And don't forget to leave us a review on iTunes or subscribe on YouTube.
Joining us again today is Tony Van Eerd.
Tony has been coding for well over 30 years
and hopefully coding well for some of that,
mostly in graphics, video, film, and broadcast at Inscriber and Adobe,
writing low-level pixel, high-level UI, threading, and everything else.
He now enables painting with light at Christy Digital.
He is on the C++ committee, and he is a ninja and a Jedi.
Tony, welcome back to the show.
Hey, great to be here. Thank you.
We have to spend some time on your ninja and Jedi qualifications.
No, you can't disclose these things.
You're not even supposed to say you're a ninja, right?
Yeah, well, I'm an upper-level ninja.
They can't complain about me anymore.
I've been doing it too long.
They're like, you're not supposed to.
That's not the ninja way.
And I'm like, what are you going to do about it?
Yeah, I guess if they say anything, you would just take them out right yeah if you could
find them you can never find those ninjas when you're looking for them that's the way it is to
be a ninja i don't know i don't know it's what do people put on their bios like none of it ever
makes sense so you know i'm a ninja, a Jedi, but we've had,
um,
yeah,
I,
I don't know either.
I always just copy and paste the bio from my last talk basically.
Cause I'm like,
I don't know.
Have I done anything new?
No,
not really.
All I do is increment that number of how many years I've been doing this.
Yeah.
It's just gone up to 30.
Yeah.
Like last time I said 25. Does that make you feel old then? Uh, I am old. It's just gone up to 30. Last time I said 25.
Does that make you feel old then?
I am old. It's not feeling old.
I don't know.
The beard makes me feel old.
Yeah, it is what it is.
I can pretend I was coding
since... I don't even know
if that year... I don't know when I started
why I think it's 30 years
because I was coding in high school. I don't know if I counted the like why i think it's 30 years because i was coding in
high school i don't know if i counted that it's probably like 30 years of all that is it's probably
30 years of professional coding that's kind of scary 30 years wow okay so so since we just uh
you know i gave my little story here about uh our my early computer use what was your first computer
uh that's a good question um that's well we did
have the original pong by the way uh my i remember my uncle got us the original pong like hardware
you know yeah we had no other like gaming or anything um and in grade 10 we uh had computers
at school came into school which, which is kind of hilarious.
My brother's two years older than me, so he was in grade 12 when computers showed up at high school, and he never got into it.
So to this day, he is still not as comfortable around computers.
And he says, it's like, that two-year gap, I
got introduced to computers in grade 10, and he just didn't.
So we forked our directions.
And yeah, we learned computers in grade 10.
And I remember taking this course where they taught like what a bus is and all the like
the hardware and the history.
And the whole time in the class, I'm like, can you just tell me how to program?
Like I saw someone else in the computer lab do the 10, go to 20,
or, you know, print out something.
And one of those, there was an adventure game of like you're standing here
and there's a window and there's, you know, pointing to the west
and one of those things.
I'm like, how do I do that?
And so eventually about halfway through the year,
I just got a book from the teacher.
I was like, give me a book on coding.
And I went off in the
summer uh and wrote mastermind in basic for like okay the pet computer or commodore or whatever
thing we had at school i had no computer at home so i had the folded printout paper with the the
holes down the side you know a big long stack of that and i wrote it out in one long sheet of paper
and it was you know six feet long of on
in pencil and it kept track of uh your it did your score and and use symbols because there's no color
like if you know the mastermind game it's like uh you know the computer guesses randomly picks
like five it's not supposed to be computer but you know two player you pick some symbols and
then the other person has to guess and you give them hints a certain way um i had to use symbols because there was no color. But I made, by the time I got back
to school, the game would keep track of your total scores over, you know, the history
of your playing. You could say how many, it's supposed to be like
five colors, but you could say how many symbols you wanted to use and a bunch of other stuff.
It just tracked everything. And I went back to school and I typed it in with two fingers
because that's two finger typing, grade 10. And I went back to school and I typed it in with two fingers, right? Because that's, you know, two-finger typing, grade 10.
And I remember it's like spending, I spent like an hour or two.
And I remember like getting tired.
I leaned back and I kicked the power cord out of the computer.
Oh, no.
It was all gone, right?
And this is on, like, you couldn't even save this stuff.
Like you saved to tape or whatever, right?
So I typed it all in again.
And then I ran it and it had one bug in it.
And I'm like,
Oh,
what's going on?
What's going on?
I'm looking at the code.
I'm looking at the code on my paper back and forth.
And I'm like,
Oh,
I've mixed up X and Y.
And I can,
I can still kind of picture the code,
all my variables,
like what the score was or how many things it was all X,
Y,
Z,
W.
There was no variable names,
right?
Like it was all because I was, I was no variable names right like it was all because i
was into math i was still considering myself more a mathematician than a programmer uh so and on
paper i think that program had no bugs i had one typo when i typed it in and it was bug free and
well been all downhill since then but my first, but you know, it was bug free because I typed it.
I, well, I did it out by hand over the summer and then all summer long, like every day that
I looked at it, I would look over it again, run it in my head, fix it, fix it.
You know, it's like people who talk about punch cards who say it has to work because
you, you know, you send in your punch cards.
Like Kate Gregory tells that of how you would send punch cards to Toronto
and get them back.
And they'd say, yes or no, that's all you got.
It was like it failed or it didn't fail.
So you had to know whether your code was going to work or not.
People with compilers nowadays and stuff like that tell them.
Spoiled kids.
Yeah.
And you get the little squiggly line saying,
don't even try to compile this.
It's not going to work.
So do you find that that though experience affects the way that you program today?
I wonder it might.
Like I do think,
uh,
I,
I do think I code,
um,
I,
I,
I bug people about this all the time.
I just say,
well,
why didn't you write it right the first time?
Cause everyone's always like,
Oh,
the first one's always wrong.
And I'm like,
well,
why don't you just write it right the first time? Because everyone's always like, oh, the first one's always wrong. And I'm like, well, why don't you just write it right the first time?
That's what I do.
But I know I spend more time thinking than I do coding, right?
And I kind of picture things before I write a line of code.
And everyone's like, what are you doing?
I'm like, I am just staring into space for a while and then be like, okay, this is how
it's going to go.
And then here's how it's going to lay out. I don't know. But I also think that's, again, it's my, I did pure
math in university and stuff. So I tend to think abstractly. I can jump back and forth. Like a good
mathematician has to be like, here's an example and here's the abstraction. Here's the example.
Here's the abstraction. So when I hire students from university for a while, I had a I basically told them that if you're a computer science student and you're in the pure math club at the university, which is, you know, why are you why are you in the pure math club?
It's like as nerdy as you can get. But you're a computer science student. You're in the Pure Math Club, I'll give you a free interview. I don't want to see your resume or anything
because a Pure Math student thinks abstractly.
That doesn't mean they're a good programmer.
But if they're also in computer science and a Pure Math student,
then I found that I didn't do this because I have a bias for math.
Maybe I do.
But I did it because after a while I realized,
and it wasn't just me, it was the people I was
working with, we realized all their best
students were, you know,
it's like, you know, do the Venn diagram.
What do they have in common? And they're like, oh,
they're all in the pure math club. So we're like, okay,
tell your friends to show up.
That's what we did. I don't know.
I do think the way people think is
how they code, right?
And if you try to tell someone to code the way you do and not the way they do,
it doesn't work very well.
So everyone's going to code the way they think, and that's fine.
I find, personally, the older I get, I was not in the pure math club.
I didn't enjoy math, really.
But the older I get, the less time I spend typing.
I'm not even going to start typing until I have a pretty good idea what my plan is.
Yep.
And some people like to go the other way, right?
They just want to feel like I need to get started.
So they get started.
Yeah.
Okay.
Well, Tony, we've got a couple of news articles to discuss.
Feel free to comment on any of these and we'll start talking more about what you've been up to.
Okay.
Sure. Alright, so this first one is an announcement on the Microsoft Visual C++
blog from Cy, who we've had on the show numerous times. And this is
about an online-only conference that Microsoft is going to host
in a week, Thursday, April 30th. It's pure virtual C++ 2020.
Very good title.
I don't even know if the conference is any good.
I want to go just because Cy came up with that title.
It's great.
But it looks pretty cool. They got
was it eight talks
by mostly Microsoft
employees, but there is also one here by
John Heed.
By John Heed Manid, yeah.
Which is pretty cool. On designing text encodings yeah text
i haven't i i don't have this visceral reaction to text like some people do um i did see a reason
you haven't done it that much i guess i probably haven't done it enough no yeah i did see a recent bug. Which means you haven't done it that much? I guess I probably haven't done it enough, no.
I saw a recent bug report on a
project I'm involved in that said,
no, it was on a bug report, it was a pull request
that said, address double
click issue on Mac.
And I'm like, yep, that's why I don't like GUI programming
right there.
I used to work at Adobe, so text
processing, Unicode, all that stuff, I knew that stuff.
And for a long time, I just wouldn't admit knowing it, because then someone's going to ask you about it.
And now I can just say, well, I've forgotten.
So I can say I used to know it.
It's not fun.
I have a friend who's intentionally leaving DevOps off of his resume right now now just because he doesn't want those calls exactly yeah great okay uh next one we have is modern cpp starter which is this
project on github and it's basically just a template for if you want to create a new C++ project using CMake, and it's all hooked up to do CI, Clang format,
all these other great things that you should have
in your C++ project if you're starting new today.
And I saw, Jason, you actually have something similar, too,
that you just updated, right?
Yeah, yes, I do, yeah.
But we don't need to talk about my project.
We can talk about his.
Well, what did you think of this one?
I mean, it looks good.
It's like most of the things that I care about.
It's got all of the tools enabled,
and I'm trying to find the list of warnings that he has on here,
or he or she, so I don't know who actually worked on this.
But yeah, I mean, I'm always a fan of this kind of thing
that helps people get up and running faster
with C++ tools, you know?
Yeah, I looked at it too, and it was just like,
I'm mostly, just because of the work I do
and places I've worked, I'm mostly on Visual Studio.
So CMake is another one of these things I shudder at,
but it is the best of the worst kind of thing.
Everyone hates all build tools,
so CMake seems to be winning.
But I looked at that and I was like,
if I had to start something new
and not in the Windows world,
I would not know where to start.
So having a place there where it's just like,
hey, start right here. Here's all the pieces.
I'd be like, hey, I could use that.
And people probably look at me thinking,
oh, you're supposed to know these things.
I'm like, no, I don't know.
Build systems and things like that is another thing that I avoid purposely.
Yeah, I spend most of my time in Windows Visual Studio as well.
Although I will say say you know they
have added lots of great support for cmake so i'm guessing if you wanted to you could do a file new
project using this sort of template and then be happy in visual studio using their cmake support
probably yeah yeah okay and then last thing we have uh another conference announcement announcement is uh meeting c++ 2020 uh it's going to be november
12th to 14th and a couple i think the keynotes are not announced yet but uh call for for speakers
is that right as well yes yes and what makes this stand out at the moment is Jens is planning to have a regular conference right now. Yeah.
Hopefully, you know, we're going to be approaching normalcy by then.
He has to start, right? Like it takes so much planning to put in, put out a conference. He
has to start now with the assumption of, you know, things will be better. And if he doesn't start now,
it's not going to happen it's
uh unfortunately i'm almost guaranteed to miss that conference i would especially this year
when we're in this drought of conferences i really want to go it's the same time as a committee
meeting so if i'm traveling at all i'll probably go to the committee meeting um which talk to
jens about that about like hey you're going to miss all these regular speakers he's like that
is great i don't want to have just the regular speakers. He's like, that is great.
I don't want to have just the same speakers over and over again.
He gets a different, you know, another good crowd of speakers because people on the committee are not necessarily good speakers either.
So it looks like, I think, I told him already, it's like either no one's show up because, because things won't be back to normal yet,
or it's going to be packed because we're,
we're all dying to go.
We're all starving for this for a conference.
So I hope it works out great.
Yeah.
So one thing that you should add to your resume,
Tony,
since you know,
you just said not all committee members are great speakers is the,
the height of the stack of awards
that you have won from c++ now yeah what is if you were to stack them up it's probably at least
a foot right you know what though i think uh that connor guy you know who showed up uh and they came
up with new awards and it's like a total they they've now, I think it's Illuminati or something.
They like, Connor won like five awards in one year because they, you know, the one award's called Your Name is Connor or something.
I don't know.
But they had like the new speaker award.
I can't win that one.
Things like that.
So, and also, I'm sure you're only bringing this up because I still didn't win best speaker that year that you won best speaker.
Yeah, yeah, yeah.
Well, no, that actually isn't why I was bringing that up, but it is true.
But you actually have won many awards from speaking.
I guess so.
He has.
He's downplaying it.
He has.
Depending on who you talk to, the awards at C++ now are known as the Tonys.
Well, that's the problem. Now they're known as the Connors.
They were known as the Tonys.
That's why I was excited to go back and reclaim my throne,
but I have to wait another year.
Since we're talking about your talks, Tony,
when we last had you on, it was right after your first post-modern C++
talk, and you've given a few
more versions of it since then,
which are always popular, including one
at the Prague Avast meetup.
How do the
different iterations since the first
talk differ?
I don't know if anyone will notice the difference between
the three talks, other than I rhyme
it now.
The talk, I don't know if anyone will notice the difference between the three talks other than I rhyme it now. The talk, I don't know why.
This is a weird.
I shouldn't even tell people.
It's better to have them be surprised.
But that postmodern C++ is the talk that was my best attempt at getting the best talk award that jason stole from me jason ben
right i think yes it was ben yes you can blame ben more than me i think so i gave that talk once
but people really i don't like giving the same talk twice because i've done it and i don't do
it as well the second time because basically i'm bored and it's not even that I'm bored. It's that, uh, I, most of my
talks are written like way too much percent the night before. Um, so it's, or like, it's like the
two days before I barely sleep and I pack in my whole talk. Um, so they're all fresh in my head.
So if I give the talk a second time, I end up looking at my own slides going, what was I trying
to say here? And I, like, I just can't give a talk well. And I try, I look at my own slides going, what was I trying to say here? And I just can't give a talk well.
And I try.
I look at my slides before and say, okay, remember what this was all about?
And then I get up there and I'm like, I don't know what I'm talking about.
So I don't like to give the same talk twice.
But people were like, oh, that was a really good talk.
You should do it again at CPPCon.
And I was like, yeah, I should.
I'll have to change it though.
I remember going for walks at night thinking, how am I going to change this talk? And then
somehow I had this idea of like, I'll rhyme it like Dr. Seuss. And so every night I went for a
walk and I looked at slides on my phone and said, well, I've got all my slides done. I know what I
want to say. Just make it rhyme like Dr. Seuss. So if you see the talks past my first one uh yeah it rhymes it sounds like dr seuss
um and if you go on youtube uh you will see the people complaining that they're like i couldn't
get past the first five minutes because the rhyming you know just gets in the way which is
true some people love it and some people hate it that's it that's a good sign with my talks. So I gave it one more time at Prague, which was a committee meeting.
Hannah organized the committee meeting in Prague.
It was just the last committee meeting that happened.
And then she also organizes this meetup.
And so at the meetup, she got a couple other kind of unknown speakers, Bjorn Stroustrup, Herb Sutter.
Maybe you heard of those two guys.
And me.
We all gave talks.
And Hannah's basically like, this is my favorite talk.
Please do postmodern again.
So I did it a third time.
And every time I do it, I change it.
And I actually tried to not rhyme it too much so that it's actually intelligible.
So this last version might be the uh that might
be the best version it's uh also the most condensed version i kind of shortened it up and
and tried to it's kind of weird because i still don't know what the point of my talk is um but
every time i give it i realize different aspects of it that are like oh this was my point i'm trying
to get because it really is it's just like layers of meta and stuff.
And even after the talk,
someone asked me a question about it.
I'm like, no, no.
Okay, here's the real point of the talk.
And then I'm like, wait a second.
Every time I, like, I'm gonna have to do the talk again
because I do actually at the end of the talk explain
because I realized people aren't going to get the points.
So I explain the points over again.
It's like telling a joke and then explaining the joke.
And then you're like,
it's not funny anymore.
Um,
but I think if I ever do the talk again,
I will again explain like,
here's why I used humor in the talk.
I'm going to like really wreck it by explaining humor and why I used humor
and what the meaning of the humor was.
And,
but you know,
it's kind of like this,
uh,
uh,
maybe this is the talk i will forever change
every time i was just like over the years it'll just the one that one talk i go back to and
and uh and you have to watch the mold to get the full experience that's what i should really do is
like plant maybe maybe i've already done this let's just pretend i've already done this oh yes
certain things in the talk so that you don't actually get the full true meaning of it like
there's there's hidden messages in the talk and you won't see the end of the message until
yeah yeah you have to watch the seventh version before you get the full
true meaning of the talk yeah edit out anything where i said maybe i should have it that's what i
did it's like the uh i don't remember what is it they called the treasure the secret it's the secret i
think it's called the secret it's a series of novels or something and there's a bunch of clues
in them and then people are going around the world trying to find where these hidden clue boxes are
i've seen a couple of tv shows about it and it went like 20 years without any of them being found
until like a year ago and they found like two more again that's that's the layers and depths of your talks in 20 years people will discover
the true meaning of your talks it would be nice if someone eventually understood my talk
you do kind of give talks hoping that someone will know what you're talking about or you know
get get a aha moment so yeah it would be nice if someone's like oh i know what you're talking about or, you know, get, get a aha moment. So yeah, it would be nice if someone's like, Oh, I understood what you were trying to say.
I will say though, for my part, for real, I, uh, over the last few years, I quote that talk
every single time I give a class on best practices, because you had a slide up as I recall it,
that was how many times must you see a block of code before you put it in a function and i propose that to my students every single time to make them think about code organization
yeah and how many give you the right answer in a class of 20 probably about two yeah on average
but then once i show them more like hey look if you actually use functions to decompose your
problem you can make readable code.
And I lead them to more examples.
Then I tend to get more students going, Oh, I see that now.
Yeah.
Yeah.
I have another talk, um, called chief weapon, the chief weapon of programming, um, which yes, is a Monty Python, um, whatever that skits called, um, the Spanish inquisition.
Um, it's, you know, our chief, chief weapon is, and they, they have, whatever that skit's called the Spanish Inquisition no I don't know that one
our chief weapon is
they have more than one chief weapon
and it's supposed to be one
it's a skit
and as I do that talk
I realize that
my and if I look back
at some of my other talks yeah all I
one of my only points I have is just write more functions.
If you just wrote more functions, don't listen to anything else.
Here's the one takeaway.
Write a function there.
That could have been a function.
That part over there, that could have been a function.
Oh, look, another function.
And I'm doing it at work now in Code Review.
And it's to the point of taunting my poor student that i have right now
i'm just like oh so like we could maybe move this and put it in a in a what a subroutine what do
you call these things and he's like a function like yeah what a great idea that's you know
but he walked i'm pretty sure he's gonna, you know, thinking I should put that in a function.
I'm like,
okay,
they're good.
I've,
I've succeeded.
So what do you pick them,
pick on them to get that stuck in their head,
but whatever.
Do you have people that complain,
but,
but that's just a small function.
It's going to add too much overhead and calling it.
I don't have people at work.
People.
I mean,
it's,
it's actually bad.
Most of the people I work with don't ever
complain about things I do because they're like
oh Tony you're on the committee and blah blah blah
it's like they should right they should question
and every now and then someone
will question me but they're too often
just accept me as dogma or something
which is bad
but yeah when people are like
this is going to have overhead and all that
and even getting a huge topic of exceptions or all these other things
that cause overhead, um, most of your code doesn't have to be fast.
Um, which isn't true for everyone.
Right.
But it's true for the average application.
And even people on the committee, I've said that too.
And they just look at me funny.
It's like, this is what C++ is all about.
It's all about performance and everything.
I'm like, no, not for me.
C++ is about correctness.
I can write more correct code if I constrain.
The type system helps you constrain things.
So I don't know where I started.
I had a conclusion there somewhere.
Where did it go? there somewhere where to go um the uh the only thing i've seen with i had i've had in my career
uh one person i coded with who i thought wrote too many functions every function was like two
or three lines and it called another function and all it did was like check an input and call
another function and it was kind of a forest for the tree. I couldn't see what the code was doing. But beyond that, I'm
just like,
if you made this small part, I mean,
I always say, if you have,
well, it's in my one talk, too. It's like, if you
search for code for the, like, step one,
you see the phrase step one in a function?
And that means that function has, like,
four or five steps, because you had to
break it up into steps. It's like, geez.
Yeah, like, call the first function step one. I don't really care what you call it just separate this out a little bit
because it's it's too much but like i said people people think a certain way people who write long
straightforward functions they're like i want to see everything i want to know what's going on
i i've got this in my head and and i just need to you know if you break up in the functions that
means i have to think you know i've lost lost my train of thought or something like that, which is true.
Right. That can happen.
So, you know, and part of the problem is a lot of those people who do that will gladly turn it into functions after they wrote it.
Right.
But then the pressure is to not spend any more time on it.
Right. So the function gets left because it
works you move on to the next thing um so you know what can you do but i i try to like no one no one
who's thinking oh i just want the straightforward code i don't want to have to think about functions
no one goes oh i i'm not going to call a stir copy i'll just do i'll write it myself it's like
functions you already know you're happy to call
right so just pretend the function i do this i that's the other one i just did this last week
um someone asked me questions like how where do i get the you know the name of the config file
or something like that and i'm like oh there's a function for that and he's like what's the
function called i said well you know like yes it's he's like like is it called like get config
name or something i said yeah that's probably it and. He's like, is it called, like, get config name or something? I said, yeah, that's probably it.
And then he's like, how do I, like,
load the file? Like, how do I read a
file or something? I was like, there's probably a function called
read file to string, whatever,
right? And I said, just go look for those functions.
He's like, I know the functions don't exist,
but it's like, just write your code as
if those functions exist.
And then, like,
you know, he comes back a little while later,
he's like, these functions don't exist. I'm like, yeah, I know. Have you written them yet? Like,
but at any time you have a question of like, oh, what should how, you know, I need this answer.
It's like, well, pretend that function exists and then go on your way to the real problem that
you're trying to solve. I don't know. I've been looking at a lot of code lately that I see something that at one point was probably relatively straightforward. And then clearly like
they wanted to add logging in. So then there's like a logging message added in every single if
block. And I'm looking at this code because I'm tasked with refactoring some of it at the moment.
And I go, wait a minute, every single one of these if statements is exactly the same four lines. So I replaced 350 lines of code with 50 calls to a new function that I just created.
It's quite a bit more readable and more maintainable at this point.
I actually had, once upon a time, I had to write a color picker, right?
So you show the different spectrums, and it did hls and hsv and
all the different things and this was a time back when on a 386 or something where function call
overhead was bad and this had to be fast and it actually for unknown reasons it had to dither the
colors because it had to be a color picker that would work on 8-bit displays so like how do you show a how do you show a ramp of a spectrum of color when you only have
256 colors so it dithered on the fly as it was doing its thing but you're dithering knowing what
you're it's you know when you dither an image you're carrying around the uh the delta error
kind of kind of thing and you you spread the error into into the next lines when you're d around the delta error kind of thing, and you spread the error into the next lines.
When you're dithering a ramp where you know that you're going from red to blue
or whatever, cyan to HLS or whatever,
I know what the next colors are going to be,
so I can precompute sort of what the dither will be because I know where I am.
I don't have to carry stuff around and stuff.
That code ended up with 204 loops.
It was all hand inlined
because HLS is six different quadrants.
They all had to be written differently.
And five years later,
someone replaced it with a function
that for every pixel,
call RGB to HLS or HLS to RGB.
It was nothing. There was no code there. I'm like, yeah, I know. HLS or HLS to RGB. Or like, it was nothing.
There was no code there.
And I'm like, yeah, I know that's what I wanted to write.
But it was the one time I was like, no, I have to write.
You know, I was basically hand unrolling loops
and doing all this other crazy stuff.
But I remember this, people are like, this, you know,
Sean Parent, when Sean Parent has the no raw loops
is one of his sayings.
I'm like, and I've got this file over here. It's got 204
loops in it. In one
CPP file. Probably C file
actually. It was that long ago.
These days you'd have to put a comment at the top
that says, no lint
Sean Parent.
That's when
you made it. If you get a lint
statement of your own.
I guess the compiler has uh has a man the guy
retires and you already forget his name scott myers right there's a scott myers as a as a
effective compiler c++ yeah i guess before we move on from this topic i i would like to add that at
one point matt uh matt godbolt proved to me pretty effectively that any function call overhead from well-organized code
that we're talking about, almost any of it,
can be eliminated with LTO, link time optimization.
It does the right thing.
Yep, good to know.
I want to interrupt the discussion for just a moment
to bring you a word from our sponsor.
This episode of CppCast is sponsored by the PVS Studio Company. The company
produces the same name PVS Studio Static Code Analyzer that has proved to be great at the
search for errors and especially typos. The tool supports the analysis of C, C++, C Sharp, and Java
code. The article 012 Freddy's Coming for You, which has been recently posted, clearly demonstrates
the analyzer's outstanding abilities of searching typos. The article shows how easy it is to make a We mentioned that you are a standards committee member. and you'll receive a trial license for a full month instead of one week.
We mentioned that you are a Standards Committee member.
Is there anything you worked on that made into C++20 that we wanted to talk about?
I've got a few things here and there.
There's the things that didn't make it in because of me.
Okay.
I shouldn't even bring up optional reference.
I'm probably to blame for why that doesn't exist.
Yeah, we can skip that one.
Yeah, it's a bad topic.
Span doesn't have equal equal because of me, basically.
Which, I mean, that one's one of my better papers because I drew a flowchart diagram in ASCII.
I'm always proud of the ASCII diagrams.
But span is basically just the pointer plus a length.
So now I have a span of data.
It doesn't own, you know, it's a spanning over a vector or something.
It doesn't own the data, but spans over it.
And then the question was, does equal equal mean that i'm pointing you
know like two pointers are equal if they point to the same place they're not equal if they happen
that the places they point to are equal like it's shallow pointer pointer equal equals shallow so
span which is a pointer plus a length should it be shallow and say two spans are equal if they
point to the same elements or two spans should be equal if the elements they point to are equal and either one can make sense um but the chance of people mixing
them up is high and uh my i didn't i didn't actually i probably should have done a better
job at pushing what i wanted uh which is basically to rename span and decide what, this is the fundamental, it happens in code all the time
and it happens sometimes in the committee as well,
is you have a type or a class
and you don't actually know what the essence of the class is.
You don't know what this class is yet.
And span is like, well, sometimes it works this way.
It works kind of like the elements.
And sometimes over here when you do assignment
or when you do const or something like that, it works like a pointer.
Because a const span, like a const shared
pointer means you can't change the shared pointer. Well, you can change what it points to.
A shared pointer to const, you can't change what it points to. Span
in that way is shallow const. A const span,
you can't change the span, you can't change the span,
you can't change where it points to,
but you can change the elements
because it's not a span over const elements,
it's a const span over writable elements.
Whereas a const vector,
the iterator you get back,
it maintains the constness.
Vector's constness is deep.
Span's constness is shallow.
So they wanted a shallow const, but a deep equal equal.
They wanted it to compare the elements as if it owned them. So I almost don't care which way you
go, it's just like, be consistent about it. And if we had named span, spanning pointer,
everyone would think, oh, this works like a pointer, everything's going to be shallow,
I know how it works. If we named it spanning ref, everyone would be like, oh, references, those are a bit weird, right, because they just are.
And I expect this to work like it's a reference to the elements.
And then, you know, you could even have both classes if you wanted, but you would know.
And then from there, and once you get the right name, any further questions that come up, the questions are easily answered.
Because you can go back to it like, well, the essence of this class is it's a spanning pointer.
It works like a pointer that knows its length.
Or it's a spanning reference.
It works like the elements.
It works as if it owned them, even though it doesn't, or something like that.
If you can make a one-sentence description of the class.
And we had the same problem with string view or something like that you can if you can make a one sentence description of the class and we had the same problem with um string view or something like that uh like you know you you put it out and then three years later someone comes back with a with a bug report or a question
of like what happens when you pass known to its constructor and then the committee spends like
that was a huge committee group meeting in one evening.
So you got 100 people in one room.
Like, what was the cost of that to discuss this one thing about null?
And it's like, well, if we had understood what it was we were making and we understood the essence of what it really is, the question would be answered.
We'd be like, here's the thing that this really models.
And therefore, this is what you get.
And we have the same problem with optional. Optional can model a container of one or zero
elements. It can model a type T with one extra state. It's T plus an extra value. Or it can model
a deferred construction. It's it's like hey there's nothing here
yet oh now now it exists it can model like at least it has at least three or four different
models and when you make a class that has more than one model you are in trouble so and some
and some things can be um it's not that all models should be disjoint completely. You can have, in the sense of C++ concepts,
you'll always have things that model more than one concept.
But when you're thinking of like,
what is the design model for this class?
It should be very clear.
It should be one thing.
And it shouldn't be like,
well, we can use this class five different ways.
It's like, well, that makes it useful,
but it also just makes it confusing and ambiguous as to,
and even if you think oh we've
answered all the questions we have and and it models an a and it also models a b and it models
a c someone along the way later on is going to be like oh for this new thing we introduced a does
this and b does that and c does that oh what what happens to this thing that models all three it has
to now pick one it has to pick its favorite, its favorite model.
And then we're like,
Oh,
and then we're going to argue about it.
It's like,
well, we didn't know what it was to start with.
So my,
that is my general complaint with the whole committee.
And most of programming is people don't know what they're doing.
Is that,
is that a good,
let me just,
sometimes we don't know what the essence of the thing we're writing is,
which goes back to why I stop and think before I code.
And it doesn't, I mean, it's not to say anyone,
you know, not that I have the right answer for any of these things,
or that, you know, it's actually a hard problem.
It should be an easy thing.
It's like, hey, you're writing a class that does, you know,
the file class or projector.
I work with projectors, projector class.
How hard can it be?
And then you realize, oh, this is really hard to get it right.
So this is why we get paid the medium bucks.
You reminded me of back around C++17,
there was some discussion about providing begin and end for optional.
I don't even think it was in the committee.
I don't know if it was or not.
Because of the comment that you made that it can model a container of zero to one elements.
Do you have thoughts on that?
Yeah, I think I understand why that can be useful.
And among other things, you can make a really nice looking for loop that especially using the new ranged for stuff.
So basically, it's a for loop that only runs zero or one time.
Right. And it pulls the element out inside the for loop.
You now have the element, the thing that's inside the optional or the for loop doesn't run at all.
And and you fall out of the, you know, the optional was empty, you don't do the for loop.
Which is really nice, but I don't like a for loop
that doesn't actually loop.
And it's not like, well, you know,
if I've got a vector one element that also doesn't loop,
it's like, no, this is never going to loop.
We're using the for statement
because we're missing the right thing.
So I wonder if we basically need in the language better support for things
like optional.
Yeah.
The,
you know,
the scary word monad,
it would be the word to throw around,
but I'll try to avoid it.
Ben's not here to save us.
But I actually,
I was,
I was writing a,
like we have variant,
we have optional. And we're talking about writing, doing was writing a, like, we have variant, we have optional, and we're talking about doing a standard expected, which will be either a value or an excuse for why you didn't have the value.
And it's, you know, it holds one or the other.
It's basically a variant of two elements.
But it's biased to the one, the expected value, right?
The error should be the unexpected.
And we're talking about how that syntax for that should be.
And I ended up needing, I needed this class myself, finally,
for stuff I'm doing at work just where I have a queue.
If you do a queue that's thread safe,
you can't do front. To call front on on a queue you have to first check if it's
not empty and then you call front and then you call pop as a separate they're all separate
operations right right a thread safe queue that's got to be one operation because you can't call
hey are you empty and it says no and then you take the first element it's like well between those two
steps it could become empty after you ask so you have to make an atomic operation so my queue you say give
me the top element and it returns either the element or an error saying there is no top element
right there's nothing in the queue queue's empty so it returns an expected i expect an element
otherwise an empty kind of like a variant of element or empty state, or an optional. Could have returned
an optional.
So I went off and started writing
this, my version of expected,
and I ended up writing a version of
a class called either,
which is an expected that doesn't
have a bias between A and B.
It's like a variant, but for only two types.
And all the way through
doing this, I'm trying to think, well, what should the, you know, should I convert automatically to the underlying type?
Should assignment just work?
Should things just work?
I came to the conclusion that the language isn't helping me.
And probably not until we get pattern matching into the language will we, we shouldn't, I'm almost tempted to say we shouldn't
standardize
standard expected. I mean, standard expected isn't
too hard because just follow the
just do everything the same as variant and optional.
But it's almost like
we shouldn't have defined any of those
things until we had
pattern matching. Because once
we know what the syntax for pattern matching is,
then it's going to change what our api for variant and optional and expected should look like so uh
i i heard you guys wanted to ask me about some other line in the in the standard yeah someone
someone uh cued us into this here saying that you were responsible for this line in the containers
portion. Yeah.
It's actually funny that
that section of the standard
was explained
all the containers and recommended
standard vector as the container
of choice. And that's always been there
since who knows how long, probably
forever. And it was
not a note.
It was whatever they call the rest of, you know,
the main part of the standard.
It's like, what's the word for that?
I don't know, standardese?
Yeah, but it means it's, right?
A note is not, what's the word for that?
The body?
Yeah, but a note has no real meaning, right?
Yeah, it's almost like saying canon,
but there's a community term for it, right?
A note doesn't, like, a compiler can ignore a note.
A note is not canon, right?
It is not part of the standard.
Sorry, I can't think of the right word.
But this thing saying vector is the best container
and everything was like, no, it's right in the legalese of the standard.
And then I was like, it probably shouldn't be.
And it wasn't even my idea to change that.
So, you know, I know nothing about how this changed, but it does now rhyme like Dr. Seuss in that part of the standard.
And I assume that has nothing to do with a talk where I rhyme like Dr. Seuss in that part of the standard. And I assume that has nothing to do with a talk where I rhyme like Dr. Seuss.
Pure coincidence.
I claim no knowledge.
And if there happens to be slides that have the exact same wording as what showed up in the standard,
and why do I happen to know it by heart?
Remember, when choosing a
container, remember vector is best.
Leave a comment if you choose one from the rest.
I
have nothing to do with that.
That's great.
I mean, I didn't want to tell anyone that it was in there
until... It's kind of scary
now because the standard still isn't...
C++20 isn't official
yet.
Right.
Um,
but there's no way the committee is going to say no to it.
Cause that,
that would just be,
I mean,
there's no signs that anyone's dislikes C plus plus 20.
And it would be quite a thing to,
we've gone through the first level of voting and all this other stuff.
Like it would just be,
you know,
insane for,
for a country now to go,
Hey, I don't like this. i've been and yeah and i've been trying to be really quiet to make sure
that wording was in there before someone had a chance to say we should take this out because
you know we shouldn't have poems in the standard or something but it's not the only poem in there
it's just and it's only two lines um but the best part is it wasn't put in through a paper or anything.
It's an editorial fix.
You can fix editorial things.
And, you know, maybe I should try not to blame who let that through.
But you only need to talk to the editors because it's not.
What's the word I'm looking for?
It's not standard.
It's a nonstandard part of the, if it's just a note and and it's not it's not a change to the language right right it's just like
oh you should have used these words because they're better words it means the same thing
then and the the editors of the language of our standard can change that without going through
the committee don't tell me so there is a there is a sentence right before that that says,
arrays should be used when the container has a fixed size node during translation,
which I'm totally on board with.
Which makes me then question, is Vector the best container?
I think so.
It's, I mean, Yarnay has done some slides and talks before where he shows the performance of vector over all the other containers.
Over array though is, is what I'm questioning.
Oh, well, yeah, sure.
Array, array is the best if you, I don't know if there's a real difference.
I guess there is.
Array is good if you know the size.
Um, but then that means you had to think like It's just like, I just take vector.
I mean, they're both the best because it's contiguous
and everything's in the cache,
and people are all about performance,
and vector just turns out to be better performance.
And even if you're doing some inserts and all these other things,
one of the first classes I always write in a new code base
is a sorted vector class that just maintains the sort and it's faster than set or map.
Right.
So, yeah, I mean, that's why there are times that vector isn't the best container.
And, you know, in theory, there's times when list is the best container, although I haven't found it yet.
If you use, It really is.
If you use a different container than vector,
you should put a comment.
I mean, map is kind of obvious as well on hash map or unordered map.
But you should leave a comment.
If you're using standard list and you didn't leave a comment saying
why you use standard list, I'm going to question your code.
But if you leave a comment that says,
well, I need standard list because it maintains iterators
when you add and delete or has stable iterators,
which I still think is fragile and scary,
but it could be a valid reason.
And that actually, I use this now as a guideline
for all kinds of places in code.
Anytime, every code base you work on
has certain patterns that they use.
And you could argue
this is a good or bad,
you know, some patterns
you like better than others.
But for a lot of it,
it's like, yeah, sure.
That's a fine pattern.
It's the one our team uses.
Unless it's actually
a known bad pattern.
It's like, it's fine.
Our team uses this pattern.
And in the case where you decide
not to use the pattern, you need to leave a comment. Because I'm going to be like, it's fine. Our team uses this pattern. And in the case where you decide not to use the pattern,
you need to leave a comment.
Because I'm going to be like, why did you go,
like, why are you doing it B when we always do it A?
So, and maybe there's a reason.
So if there is a reason, leave a comment.
If there's not a reason, just, you know,
do what we do in Rome kind of thing.
The first C++ code base that I was paid to work on
had the standard of list is our
default container for everything yeah i wish i could go back to that code base today yeah i i
saw a code base too where they didn't trust and i i understand why in some places you don't want
to use standard containers and everything but i saw saw a code base that didn't trust standard vector
because it's a template and blah, you know,
all these, it's going to be slow and all this stuff.
And instead they wrote their own kind of vector thing
that allocated every element and stuck them in an array,
but then allocated, like, it was really weird.
And it's like, each element was out.
I'm like, there's no way this is faster.
Like, do you realize you made something worse?
And you have this headache of trying to track who is supposed to free these elements.
Yeah, so it happens.
This is why we get to go and pick people's code.
The scary part is that the world keeps running.
So much code is...
It works.
I have a separation between
code that works and code that's correct.
There's a lot of code that works.
It might not be correct, but it still works.
It's like, ah, this will have a bug
if you ever run into this case, but if you don't run into
it... Actually, the codebase I work on,
I know it has
memory leaks. I don't know any codebase that doesn't have bugs in it. Actually, the code base I work on, I know it has memory leaks. I don't know any code base
that doesn't have bugs in it. But the program that I work on is for setting up projectors and
aligning them. And we do projector mapping across. If you stick 50 projectors on a building, I will
seam it together into one big image. But that code only has to run for an hour
or something. And then we upload the answers to the projectors, and then my code stops running.
And then you can run your show for the next two weeks, and it stays aligned or whatever.
I can have memory leaks, because my code will never run long enough that you'll notice a memory
leak. I still don't like having a memory leak, but its priority has suddenly gone down.
And for a long time, I'm like, how can we live with this?
It just feels bad.
And they're like, eh, I fix them as I find them,
but I don't go searching for them anymore.
Because I know there's one here somewhere,
but we've got lots of memory and it'll never be a problem.
So the code works, even if it has a bug and the memory
leak doesn't crash like you know delete a use after delete you know is a worse bug then just
don't delete it right not a good not a good way of fixing use after delete bugs but uh you know
you heard it here tony says remove all the deletes from your code. Yeah. Just tell the user to buy more memory.
It's cheap.
Going back to something you mentioned in the links, show notes,
there's going to be a C++ meeting in November.
There was supposed to be one in a little over a month.
Is the committee making any plans to account for the you know
canceled verna meeting are you going to be doing anything online or virtually
yeah the committee committee is actually uh pretty i don't know what the word is um pretty
gung-ho or something um we're having meetings like twice a week and that's like just the library
group is having meetings twice a week and the evolution group is having meetings twice a week and that's like just the library group is having meetings twice a week
and the evolution group is having meetings twice a week and there's probably like six or seven
one hour hour and a half meetings going on every week between now and um meeting in person and it
somehow works out to a similar number of hours as uh if had met for a week, you know, in person. But it's,
I can't keep up to it. And, you know, it's, we can't win either way. Like some people were
complaining. It's like, that's too many meetings. I'm going to miss out on stuff. But the standard,
it's also too big to keep track of. There's too many features going on to keep track of it all.
So you have to just trust other people to, you know, okay, I'm not going to be at this.
And I trust you guys will make a good decision whether I do or not.
But, you know, and the meetings, the virtual meetings we're having now are not, I mean, nothing's definitive until it goes out the door.
But the meetings we're having now are not in any way final votes on anything.
They're just let's make some progress
and give people feedback on their papers. And then when we meet in person, we'll go over it all
again, but hopefully everything will be more polished because we've gone over it once before.
So yeah, we're definitely trying to keep moving. The committee is on a three-year schedule,
and we plan on releasing in three years. That's the schedule.
It might mean we have slightly less than we wanted to, but we might just keep going on pace.
I think there's a lot of... People often ask, do we need face-to-face meetings? And I still think,
yes, we do. There's a lot of value that we can't get done it's a lot
easier to get things done face to face it does there's a lot of downsides to face-to-face
meetings it means a lot of people can't show up for various reasons um it's kind of self-selective
which is bad um but it does get things done and and there's a lot of value in them so we'll
probably still keep doing them but yeah we've got this mix and uh the
varner varner one in particular is kind of funny because um you guys might know peter demov uh he's
a big boost contributor he's also the you know he originally wrote shared pointer um and so he's
written a bunch of stuff that's shown up in the standard and he is on all the standard uh emails
but he never shows up to meetings like he so, so, you know, you can be a productive member of the committee and not, and not show
up to physical meetings.
But he is in Bulgaria.
And I remember at one time years ago saying, we're just going to show up to you because
you'd never come to, you don't come to us.
We will come to you.
And then it actually started turning out.
It's like, we're going to go to Varna and Peter will be there because he's in that area.
And we'll like force him to actually show up in person.
And then it gets canceled.
So I don't know.
What can you do?
There's also a sad, really sad,
there was a bet when Concepts almost made it
into C++ 17 and then they got pulled out and then they're going to show up for 20. When they it into C++ 17,
and then they got pulled out,
and then they're going to show up for 20.
When they got pulled out of 17,
various people had friendly bets of like,
when will Concepts actually make it into the standard?
And being the, you know, whatever kind of guy I am, I said 21 because, you know, just to troll the committee.
And now I have this sick hope of uh this whole covid virus not slowing down you know because c++ 20 as far as we're concerned is done but maybe
technically iso won't be able to publish it until 21 so i still have this chance of like
you know because i think we did this once before that one of our years, you know, we voted it in the right year and then it technically published the next year kind of thing.
But we still label it 14 and 17 or whatever.
So even if it publishes in 21, we're still going to label it 20 because we were done and we voted it in in 20.
But I'm kind of secretly hoping that ISO has, you know, technical difficulties and publishes in 21.
Don't tell Herb I said this.
Okay.
Well, it's been great having you on the show again, Tony.
Yeah, yeah.
It's fun.
Anytime.
Yeah, thanks for coming on.
Yep.
Thanks so much for listening in as we chat about C++.
We'd love to hear what you think of the podcast
please let us know if we're discussing
the stuff you're interested in
or if you have a suggestion for a topic
we'd love to hear about that too
you can email all your thoughts to feedback at cppcast.com
we'd also appreciate if you can
like CppCast on Facebook
and follow CppCast on Twitter
you can also follow me at Rob W Irving
and Jason at Lefticus on Twitter we'd also like to thank all Rob W. Irving and Jason at Left2Kiss on Twitter.
We'd also like to thank all our patrons who help support the show through Patreon.
If you'd like to support us on Patreon, you can do so at patreon.com slash cppcast.
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 was provided by podcastthemes.com.