CppCast - CppQuiz
Episode Date: September 13, 2018Rob and Jason are joined by Anders Knatten to discuss the CppQuiz.org website, it's inspiration, recent updates and more. Anders is here as the author of cppquiz.org. He's been working as a pr...ogrammer since 2001, in fields ranging from multiphase flow simulations to web development. He’s been doing everything from working on compilers to being CTO, and has been using a wide variety of languages. C++ is closest to his heart, but he’s been doing other things for the last five years. He’s very happy to be back as a C++ developer from October 1, in his new job at Zivid Labs. Anders is also a father of two, and in his spare time he’s the producer and frontman of the futurepop band Modulo One. News C++ Alliance Sponsors Cpplang slack and more CMakeRC A standalone Cmake based C++ Resource Compiler Anders Knatten @knatten C++ on a Friday Links C++Quiz Non-virtual destructors Destroy All Software Lightning Talk Zivid Labs Oslo C++ Users Group Sponsors Download PVS-Studio We Checked the Android Source Code by PVS-Studio, or Nothing is Perfect Patreon CppCast Patreon Hosts @robwirving @lefticus
Transcript
Discussion (0)
Episode 167 of CppCast with guest Anders Knaten recorded September 12, 2018.
Today's sponsor of CppCast is the PVS Studio team.
PVS Studio can be considered both as a tool for finding errors and typos and a static application security testing tool.
The tool supports the analysis of C, C++, and C-sharp code.
In this episode, we discuss the C++ Alliance announcement.
Then we talk to Anders Knotton.
Anders talks to us about cppquiz.org and more. Welcome to episode 167 of CppCast, the first 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?
Pretty good. Getting ready for CppCon. How about you? I'm doing okay.
We do have a pretty bad storm bearing down on us in the Carolinas, though.
It's beautiful weather out today, but it's supposed to be hitting tomorrow night, I believe.
It's just some little tropical thing, right?
It's a Cat 4.
Cat 4 hurricane, so it could be bad.
I've been tracking the weather regularly on my phone, looking at the satellite.
They call it the cone of uncertainty.
And two days ago, the center line of that cone was literally going right through my town.
But it has since shifted further and further south.
It's currently aimed more at South Carolina.
I think the whole coast
is still going to get hurt pretty bad and we'll probably still get some heavy rains and winds here
um and i think i am probably going to actually edit and publish this episode tonight instead
of tomorrow in case i lose power so when is it actually supposed to hit you i believe it's
supposed to start thursday night into friday okay something you know what is
the current forecast i'm curious for how many what the wind speed will be when atlanta makes it to
your area i don't know what it'll be by the time it gets to our area but i know it's got like 140
mile per hour winds right now 140 okay pretty bad i saw someone one of the astronauts up on the ISS shared a picture of the hurricane, and he had to use a wide-angle lens in order to see the entire hurricane from space.
Wide-angle lens from space?
Yeah.
So that's about 200 and something kilometers per hour for our non-US listeners.
Yeah. yeah so yeah anyway if you're listening to this episode early on thursday instead of friday and
you're wondering why it's because i'm uh worried about possibly losing power later this week
right yeah well good luck thank you well a top episode like your piece of feedback uh this week
we got a tweet um from ama and the tweet was actually written i believe in arabic but uh twitter has the lovely
translate tweet button which works pretty well and uh he you know made this tweet about how he
loves listening to technical podcasts and said that he's currently listening to the archive of
cpp cast and cpp chat and they're easing the burden of congestion and i looked it up and he's
from kuwait well yeah we got listeners all over the place.
That's cool.
And I know absolutely no Arabic whatsoever.
No, I mean, it's a very unique, different language compared to English.
I guess I actually know a few spoken words, but I can't read a single character of it.
Neither can I.
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 cpcast.com.
And don't forget to leave us a review on iTunes.
Joining us today is Anders Knotton.
Anders is here as the author of cppquiz.org.
He's been working as a programmer since 2001 in fields ranging from multi-phase flow simulation to web development.
He's been doing everything from working on compilers to being CTO and has been using a wide variety of languages.
C++ is closest to his heart, but he's been doing other things for the last five years.
He's very happy to be back as a C++ developer from October 1st in his new job at Zivid Labs.
Anders is also a father of two, and in his spare time, he's the producer and frontman
of the future pop band Modulo One.
Anders, welcome to the show.
Thank you.
Glad to be here.
That sounds like there's a lot going on, but I do want to ask, so you say you're just now
moving back into C++ development.
How long has it been since you were doing C++ professionally? I think it's actually 2013. It's the summer of 2013.
So about five years. Yeah, that's actually the same summer that I launched CppQuiz,
not knowing that I would depart from C++ professionally at that time.
But yeah. So is your move back into C++ directly related to your work on CppQuiz?
Well, kind of.
I've been kind of forced to keep up with C++ at least a little bit because of the site.
When I decided to find something new, C++ was kind of a natural thing to go into because
I had a quiz I had a blog and I know a lot of people and I really like a lot of people in the
community and yeah so I've always kind of felt at home with C++ and I went to my first C++
focused conference for five years just a few weeks ago and it was just like, yeah, I'm back. It was really nice just to see everyone and get back to the things I'm mostly interested in.
I would think that it would be hard after five years away to get another job using C++,
but on the other hand, since you've stayed connected to the community for the last five years,
that must have made it much easier. Yeah, I think the job I got was,
I had two people I knew who knew people there,
and so that kind of set that deal up.
But also having still blogged a bit
and having the CPP quiz just made it quite easy, actually,
because I would say, hey, my name is Sanders,
I have this site and this blog and stuff,
and they go, okay, we'll talk to this guy.
It's
one of those things where you have this privilege of
actually having the time to do those kinds of things,
which make people notice
you.
So, yeah.
I guess that's
a good reason if we have any
listeners who have been thinking about blogging
or starting a project and haven't
yet, you should. yeah yeah i mean not not everyone are fortunate enough to have the time to actually do
all of these things uh but uh yeah this summer i interviewed with actually a lot of places uh
because i really wanted to find something really cool to work on and i noticed it really helped to
have something to refer to.
So here's my quiz site, or here's my open source stuff, or here's my blog, or something
like that.
And also having worked with recruiting myself, you tend to notice these things, I think.
But it's also an important bias to be aware of when you're recruiting people, because
not everyone has the time and possibility to do all these things,
but they can still be good programmers.
So it's important to be aware of, I think.
Yeah, that's a good point.
Yeah.
But if you can, do it.
Definitely.
Okay, well, Anders, we've got a couple of news articles to discuss.
Feel free to comment on any of these, then we'll start talking more about CppQuiz, okay?
Yeah.
And it does seem that our news is a bit light
lately yeah i think that might just be kind of leading towards cpp con i'm sure there's going
to be a lot of news afterwards it's also just the end of the summer and schools are starting back up
so people might just be busy maybe not news for those reasons it's interesting to to ponder how
many people might be holding news back because they're waiting until they're talking CBP con or product announcement or something like that.
Right.
Well, anyway, this first announcement we have is C++ Alliance.
And this is a new nonprofit organization that's going to be kind of just promoting C++.
I'm surprised I haven't heard about this before.
I imagine this maybe took a while to set up.
But apparently they're going to be sponsoring C++ or CppCon.
They are now sponsoring the Slack, the CppLang Slack.
And they have staff engineers, including marshall clow who's been
a guest on the show and damian jarek uh i'm not sure what exactly means to be a staff engineer
like are they actually employed by the cherry like that's their full-time job i'm curious about that
i don't i have no idea and marshall works on several open source projects boost related things
so i could totally see him being funded full-time to work on things but i have no idea. And Marshall works on several open source projects, boost related things. So I could totally see him being funded full time to work on things,
but I have no idea.
I was kind of most curious about that.
And it,
yeah,
it says he joined as a staff engineer and it says previously he worked for
Qualcomm.
So is he really leaving Qualcomm for C++ Alliance?
I want to find out that.
Oh,
yeah,
I don't know.
Yeah. But yeah, it sounds pretty exciting.
This new charitable group working to empower the C++ community. So, I mean, the main
news items here is that the C++ language slack is
funded now. Right. So we we had a problem with history now we do not
have a problem because there was a limit if you're using the free version of slack of like what 10,000
messages be backed up or something like that is something like that and the rate that most
messages were being uh posted it was basically any particular channel didn't have a history of more than something like about 36 hours.
Oh, wow.
Okay.
Yeah, that's how quickly it was getting to the end of that.
Oh, and I did notice on the news on their website that they are over a year old.
So have we really just been like under a rock or something?
Like how do we miss that if they've been a year old?
I don't know. It's I don't know. Have we really just been under a rock or something? How do we miss that if they've been a year old?
I don't know.
I don't know.
Did you read the first comment from STL on the Reddit post?
I did read through some of that.
He was kind of commenting a bit about their website and things like that.
So he comments that there's a video reel that had been playing on the website that had snapshots of several C++ speakers.
That, he says,
it creates an impression of association or endorsement,
which doesn't seem to be proper
if the speakers weren't asked for their approval.
So he was one of the people in that snapshot.
I was apparently caught up in this also.
I did not know that I was used on a video reel
on their website not that you're necessarily offended by that but yeah it would be nice to
know yeah they have since taken down that video reel because of the uh the minor controversies
surrounding it well we'll have to talk more to some people involved in this to get a little
more detail about it uh john callb was a board member, so was
Vinnie Falco and Rene
Rivera. Yeah, and Jens
Veller is involved as well. Yep.
Yeah, well, I'm definitely
curious about this. I want to get some more info.
Anders, did you hear about this
before, like this week?
No. Yeah, so I
don't really know any much more than what
you do. Okay. That would have been hilarious. Yeah, so I don't really know any much more than what you do.
Okay.
Yeah, it would have been hilarious.
It's good that Slack is funded so we get history.
Otherwise, I don't really know anything.
Right.
Okay.
Sorry that I interrupted you there. No worries.
And the next thing we have to discuss is uh cmake rc which is a standalone cmake based c++
resource compiler yeah and i think we talked about resource compiling a bit um oh i just forgot our
guest name um but when we were john heed we're talking about him with uh talking about stood in
bed with him.
And that seems to be kind of in the same vein as what the CMakeRC is trying to accomplish.
Well, I mean, you're a Windows developer.
Resource compilers are a normal thing.
Yeah.
Right.
I think that there's a slightly different thing here
because it would be like a constexpr embed kind of keyword
added in C++ if John Dean's proposal goes through.
Or a constexpr function of some sort.
But same, yeah, basic kind of concepts.
I looked through all this and I'm like, I think I'm going to start using this in about two days on the project that I'm currently working on.
Thanks.
Yeah, it did look pretty cool.
And I will probably read,
I skimmed through the blog post I made
about the first implementation
and I'm probably going to refer back to that
when time comes that I need to write some CMXF myself
because, yeah,
it seems like there were a lot to learn
from that post as well.
So is that a blog post,
where's that blog post that you referred to?
It was referred to from the readme i think uh okay they had a blog post about the pre 2.0 version i think that they
were explaining how they made it okay i said that the current one is a bit different from from that
but it's kind of on the same uh in the same spirit so yeah i think it's probably going to be something
to learn from and considering that this is actually compiled into the binary,
I do wonder how much of this is constexpr
and how much of it could be constexpr,
because I want it constexpr.
Actually, for the projects I'm working on right now,
constexpr and that would be irrelevant.
But for some projects, I would want it constexpr.
Okay, well, Anders, why don't we start off?
We already mentioned
CVP quiz a little bit, talking about your
bio, but can you give us an overview
of what exactly CVP quiz is?
Yeah, it's
what it says on the
tin, it's a quiz about C++.
So you go
to the site, you get some
C++ programs thrown at you,
so you get a complete program,
usually between maybe 15 and 30 lines
with a main function and everything.
And your goal is to figure out
what's the output of the program.
And sometimes it doesn't have an output
because it's a compilation error that you have to find,
or sometimes it's undefined behavior,
sometimes it's implementation defined
or unspecified behavior. And then you have to have to select that okay this one actually it compiles but it
has unspecified behavior um but i try to keep most of the questions to questions that actually
compile and are well defined and have a determined deterministic output uh so you can just keep going
through all those questions or you can like say start a quiz and then you get 10 questions
randomly selected and then you're done you can share the link with your friends and
see uh if they beat you and you get the score at the end so yeah that's i guess that's uh this of
it so those are the four specific options it is unspecified undefined compile error or yes it
produced output and this is what it is yeah you select those from a drop
down and then you have to fill out the output in a little text box so it's usually like the output
is usually just like one or two or three characters based on which overload was selected or
how many times the copy constructor was called or yeah okay like that so the output is typically
a or one two three or a a b or something like that
based on what happens in the program so it's yeah it's it's a simple format but not very easy
always uh no i mean we'll dig into it to more some more but i will say i have tried to do some of
them and some of them are challenging it's subtle some of them are quite. It's subtle. Some of them are quite subtle. Yeah.
If you challenge me to do it now,
I could probably not solve all the questions myself either.
Because at some point,
I understood everything going on in all the questions.
But yeah, some of it is really hard.
And some of it is contributed by other people.
In which case, I make sure I understand and I read the standard.
I make sure I really, really understand it at that time.
But a few years later, then, yeah, you forget.
The standard's only like 1,200 pages.
Surely you could just have it memorized by now.
Yeah, the C++11 standard was 1,400, I think.
I don't know how long the 1,700 is.
Oh, right.
Well, I mean, I guess we already alluded to this earlier,
but how did you decide to start the project?
I was at the ACCU conference in England in 2013, which is a really cool conference.
It's kind of small, I would say, or maybe I've been to some really big ones.
I don't know how, a few hundred people.
And everyone is in the same hotel so basically
everyone hangs out in the evening and it's a very like a nice uh nice atmosphere and lots of
interesting people and uh there's a guy called oliver mardal from cisco in norway he used to
have his zipless pub quizzes and they were really really fun i have heard of those yeah and it so his format is
basically the same as mine he will show a tpls program and you have to figure out what's what's
going to be the output but in his format the he he tells you his compiler and his os and the
question is what's the output on my machine so that makes it really interesting for like an
interactive format
because you can both discuss, okay, what does the standard say?
But you can also discuss, huh, so what's going to happen on his computer?
So he calls a function with a local variable that he sets
and he calls another function with an initialized variable
and then that has the value of the local variable from the other function
because it just reuses this.
So then, okay, so the output is actually three even though it's an initialized but of course it's undefined behavior and so you get these fun discussions um and yeah and when you do it at
the accu conference then you have people like bjarne himself and people in the in the other
teams that you can compete with so So the competition is pretty hard.
But yeah, I've been to one of those,
and then I've been to the pub for a few more hours,
and I got back to my hotel room and was thinking I should sleep.
But instead I figured, hey, someone should make this thing online.
And yeah, so I started the prototype instead of sleeping, a bit drunk.
And that was fun. So I kind of finished the prototype on the train and the plane back home two days later.
And yeah, then I figured I should actually finish this.
So yeah, instead of cleaning it up, I just added the rest of the features to the prototype and shipped it.
So it's not the best quality of the code in the implementation of the features to the prototype and shipped it. So it's not the best quality of the code
in the implementation of the site.
But it's been up and working for five years
or more than five years now?
Yeah, it's technically one of the worst projects I've made.
There's no CI except for me running things locally.
And yeah, there's no load balancing running.
It's just running on a shared server in Amsterdam somewhere.
But it's a very small
easy project.
It actually has great uptime and it
rarely fails, I would say.
I don't change it that much either.
So, yeah.
So, one
important difference from all of these quizzes is that
the CPP quiz always asks about what does the standard say.
Okay.
So I think that makes more sense for that format where here is the correct answer.
Where you don't have that much interactive discussion, I think that's better.
But for the pub quizzes, it's really fun with the part with what's going to actually happen on my computer part.
Yeah, that's part of the fun. fun yeah i've never really thought about that i'm still my brain's just a
little bit stuck still on the what does it do on my computer the deterministic undefined behavior
basically yeah like i know with this compiler this is always going to happen because of the
way it manages the stack but it's undefined behavior that's yeah
and then the correct answer is is three but you get i think you get bonus points if you can then
explain also that it's actually undefined behavior but it's going to print three on your computer
wow yeah yeah so that's that's how it uh started and then i kind of uh of just kept going with it. So CPP quiz doesn't really have those kinds of questions, really.
It's of the what would it do on my computer.
No, no.
All the questions are what does the standard say that's going to happen.
And in the beginning, I didn't always have references to the standard,
but all the questions over the last few years
have really detailed references to the standard, but all the questions over the last few years have really detailed references
to the standard with quotes explaining why the particular thing is going to happen.
So when you manage to get it correctly, then you can read the explanation about, okay,
why was this?
Why is this the case?
Or if you give up, also you will be shown basically almost a blog post sometimes about
why is this the output of the program?
Cool. basically almost a blog post sometimes about why is this the output of the program cool so were a lot of the questions still like inspired from the pub quiz directly uh how'd you go about creating
them all uh yeah some of them like although was like he's a really really nice guy and he's been
running the oslo c++ user group for many years as well uh he just sent me all this material and i was free to steal from him and i also got a lot of help
from other people in the ssu so on the mailing list people sent me some of the stuff they had
used for quizzes in their companies and stuff like that so that was kind of seeded the whole
thing with enough questions to publish and then later is a lot of it is just me reading something somewhere
thinking hey this might actually be a bit confusing for someone let's see if we can put
it into a question and very often it's actually i'm reading the standard because i need to understand
the reasoning for a question i'm working on and then i just read a sentence and say hey
that could actually be a new question so So, yeah, today I was just randomly
reading the fact that
if you copy an initializer list,
it doesn't actually copy the elements
that it's referring to.
So then, okay, that's a new question.
Then I can put an
object in an initializer list
with a side effect in the
copy constructor and just
pass it to a function by value a few times
and then the user has to figure out,
okay, does it actually copy it when it goes in there or not?
So the copy constructor will just print one or something.
So yeah, that's often how it happens.
At one point, I decided I would save some time
and I would allow other people to contribute questions.
So I made a form where you can enter a question and the explanation and the correct answer and everything.
The problem is, of course, that people then submit questions about things I don't know.
And I have to understand everything in that question completely with how does the standard actually say that this is actually the only behavior that's allowed?
So I can often spend several hours just reviewing one question from a user.
So I didn't save any time at all.
So you already said that this is the worst project you've ever written,
but do you by any chance have a workflow or something?
So when this comes in, you could send it to other people for review or have other like people help you review the questions
uh i haven't really set it up like that now i did make a separate setup now for for porting
all the questions to c++ 17 but other than that it's just a web form and it goes into the database
and i'm the only administrator. So I have a little
mailing list which I almost never use
but if I really get stuck I ask
there but recently I've been
asking a few times on Stack Overflow as well
and I always get this
language lawyer tag applied to
all my questions. Not sure if it's an insult or
if it's just
informative but yeah.
That's how it goes.
So what if...
Oh, sorry.
Yeah, go ahead.
I was going to say,
what if someone finds a bug in one of your questions?
Yeah, that happens.
Usually, every time I publish a new question,
I post it on Twitter.
And if I make a mistake,
I typically get to know in a few hours
by someone on Twitter.
Okay.
I also have a GitHub repo, so people log issues on GitHub.
And some of the bug reports are real.
And actually, quite often they are, hey, I tried this in my compiler and it says something different.
So the quiz must be wrong because uh gcc surely has discovered right and uh and often
actually that's just because it's undefined behavior but yeah you reuse a variable or
something like that so so the compiler side there's no bug like they are just doing whatever
and it's legal and it's something different than the site says because the site says it's
undefined behavior and someone says no it's not my compiler says it's legal and it's something different than the site says because the site says it's undefined behavior and someone says no
it's not my compiler says it's the answer is
a b 3
yeah right
so but yeah I get
I do get real bug reports
as well and that I have to
fix and
yeah sometimes actually bug
reports to the quiz end up as
bug reports for clang or GCC.
There's one question that I've had multiple bug reports about,
and I think Clang and ZipBeeQuiz are correct and GCC is wrong.
But there's a bug for GCC saying that Clang is correct,
and there's also a bug on Clang saying that GCC is correct.
And they're both open.
But I'm pretty sure Clang
is correct.
But it's about the corner case, I think.
It's not very important.
In my experience in the corner cases, if Clang
produces one output different from GCC,
Clang is more likely to be the
correct one, but...
Yeah.
It's usually things that don't affect real code.
Yeah, it's like this is using a decal type
on a variable inside of a lambda and the variable is actually not captured by the lambda
so it's not odr used inside the lambda and then it shouldn't be captured but there's a specific
little clause somewhere saying that if you put decltype on something that was
captured,
but isn't ODR used, it should be
as if it still was ODR used.
So it's like,
the decltype has wrong
const. So it's not like,
it's not the end of the world, I would say.
But it's, if you want to,
I think it's question 127
if you want to look at it later.
Okay.
But yeah, it's details like that.
And I don't think that's a very particular,
like it's not a very interesting question in that case.
But yeah, sometimes stuff like that happens.
And typically this happens
when there are some really smart people
who know a lot more C++ than me who contribute a question about some very esoteric stuff. Link to the distribution package is in the description of this podcast episode. You might not even be aware of the large number of errors and potential vulnerabilities that the PVS Studio Analyzer is able to detect.
A good example is the detection of errors that are classed as CWB14, according to the Common Weakness Enumeration.
Compile a removal of code to clear buffers.
PVS Studio creators demonstrated the detection of such an error type, for example, in one of the latest articles,
We Check the Android Source Code by PVS Studio, or Nothing is Perfect.
Link to this article is also in the description of this episode.
PVS Studio works in Windows, Linux, and macOS environments.
The tool supports the analysis of C, C++, and C Sharp code, and Java support is coming soon.
Try it today.
How many questions do you have in total on the site?
Because when I was looking at it earlier, it said that, you know,
I did one of them and then said one of 95 questions correctly.
But you're saying there's at least 127.
How many are there?
Yeah, no, there are 95 published questions.
95 published ones, okay.
Yeah, so 127, that's including some spam i got before
i set up spam protection and some questions that i refused people often um sometimes they contribute
questions where the answer is just wrong where they rely on ints always being 32 bits or yeah
rely on alignment and padding always being in a certain way because that's how they
got it on their machine.
So there's some of that, some spam,
and also some I've just retracted later
because they were unclear or stuff like that.
So 9 to 5 published questions.
I think I have 10 in the pipeline that I have reviewed
but not published yet,
and probably quite a lot of half-finished questions from myself.
I try to prioritize when I get stuff in from other people
that I prioritize reviewing that first
before I start making more myself.
But yeah.
So how much do you think the questions tend towards
the esoteric corner cases
and how much do they tend towards practical, useful knowledge
for C++ developers?
Way too much towards esoteric.
Okay.
And I think that's often because people find that,
like people who decide they're going to contribute to C++,
those are a certain kind of people, I think,
who are very interested in esoteric things about C++.
Like your normal C++ developer
wouldn't probably contribute questions to that site.
So I think I kind of get a bias of who is actually going to contribute.
So what I want to do is to try to get more simple questions in about practical stuff
that you actually either need or that's actually interesting and will,
when you understand the answer, it's going to teach you something that you can use in other situations.
And I do have like a difficulty setting.
So each question is like easy, intermediate or expert.
And I need to get more easy questions in so that I can put up a filter so it can say only show me the easy questions or only show me easy and intermediate questions.
Because then a lot more people I think will find it useful and not just give up.
I often give up
myself on questions
that I get submitted from other people
so yeah
I need to get more simple questions
but I also sometimes get
people contributing a question such as
see out high
and that's too simple
it has to be
at least two ways of reasoning and it's
almost
you have to be able to
think of at least a few alternatives
that could be the answer of the program
yeah
if it just says C out
high then there's no point
there has to be some sort of thing that you
have to understand because either it's this
then it's A or it's the other way around and then you get b or something it has to be something
you can be tricked by kind of but it can be it can be much simpler things than which which
function is going to be found by a template when it's not hasn't been instantiated yet but it's
dependent on some other template that's like yeah yeah yeah a lot of the questions are like that and it's just too hard for for
people who don't actually actually implement compilers i think right including including me
uh i don't implement compilers i don't understand their questions either
plus it takes me it takes me four hours to understand and rewrite the answer to refer to the standard.
I'm curious, though, since you said some of the questions make assumptions about alignment or about the size of an integer, that kind of thing.
And I wonder how much your exposure to the CPP quiz is going to affect the way you actually program in C++?
Are you going to be super defensive programming all the time?
Or do you know the places where you need to be concerned about all these things?
I don't know. I think it's made me more afraid of C++.
That's terrible.
It's kind of an important
fear, I would say, that I try
to impose on my co-workers.
But
you have to be careful
with C++, because
I had a lecture when I
started with C++ in college, and
when someone asked,
how does this work? He would often say,
try it out, and find out how it works.
And that's the worst advice you can give about C++
because if you try something,
you don't necessarily get the correct answer.
So does a local variable always get initialized?
Oh, yeah, because you happen to get your memories here
before you started the program.
And then people think, okay, yeah, so my...
Okay.
All variables are zero and initialized, for instance.
So, yeah.
A little bit of healthy fear of the language, I think, is good.
That's interesting and a little sad at the same time.
Yeah, I've been thinking, like...
I've been writing a few other languages
and people have said you should make one for C Sharp
or for Python or something, and
I don't think there are many languages
that would be so easy to
make that kind of quiz for.
Because I don't think, I can't think of
at least any other language that's so complex
and so full of undefined
behavior and complex corner cases and
weird stuff.
Yeah. I've seen some of those posts online,
like programmer humor,
like what does JavaScript do here?
It's like one equal, equal,
quotes around one, things like that.
You could make some fun ones with JavaScript.
Yeah, the Watt talk by Gary Burnett.
Yes, that's a classic.
Yeah, so
there are things in other languages as well,
but Steve Bliss is just so huge
and so strange.
Yeah, what is it?
Go ahead.
I was just going to say, if our listeners aren't familiar with the talk we're
talking about,
what's his name again? Who did that
JavaScript talk?
Gary Bernard.
Okay. And it's, if I recall,
like a lightning talk. It's only like 10 minutes long or something.
Yeah.
Yeah, go watch it.
Destroy All Software is his
vlog kind of thing.
Okay.
So yeah, if you search for Destroy All Software
and Watt,
W-A-T,
you'll probably find it.
It is a very, very entertaining, well-done lightning talk.
Yes, it's one of the most entertaining ones I've seen.
Yeah.
Sorry, go ahead, Rob.
I'll put a link to that one in the show notes.
I was just going to say, so you've been running the site for about five years now.
Do you have a Patreon or anything to help you with website hosting fees?
No.
Maybe I should.
A few months ago, I figured out I was going to go back into C++. I started
watching C++ Weekly.
And I noticed the Patreon thing was going there.
And I might try to do something
similar. It's not very
expensive, so since it's just a shared server in Amsterdam,
it's not like a big cloud data center thing.
But still, it would be helpful for hosting fees
and maybe to help with buying new versions of the standard
and some other costs.
It's interesting that it's a shared, hosted
server in Amsterdam. You've said that a couple times.
Is it just so controversial
you needed to put it into a neutral country
or something like that?
It's because that's their
Europe data center.
I'm using someone called
WebFaction.
They are great.
They have a really great support.
I have no idea if they're cheap or expensive
or anything. I set it up five years ago and I haven't
really compared to Animal Health since then.
Every time I have a question, I send them an email
and they
fix it in 20 minutes on a Sunday.
It's
really great support.
I really recommend WebFaction if you need
similar stuff like this.
That's cool. Have you had any problems
with when you get posted on Reddit or
anything, like server performance
degrading or anything like that?
No. That's cool.
Yeah.
The site is very lightweight and
the other thing is that people don't click around a lot.
I mean, you click on a question, and then you look at that one for five minutes before you click the next link.
That's true.
Right.
I don't remember the numbers, but I looked at my – I have some Google Analytics stuff,
and I like the average visitor time is like 12 minutes or something.
And that's including everyone who just clicks away.
So most people, they stay there for a really long time
and they don't click that many links.
Like an hour writing out the thing,
trying it on Compiler Explorer,
trying to figure out what it's doing.
Yeah.
Yeah, I haven't had any issues with that,
but I don't think I've gotten
that huge amount of traffic either.
So you recently announced that you're putting out an effort to try to get all the questions
updated to C++17, is that right?
Yeah, so everything has been C++11, and all the questions have typically from one to five
references to the standard.
So I figured at some point I need to start targeting C++17.
And some of the answers might actually have changed.
One of the more esoteric questions was about the trigraphs, for instance.
That one just had to be changed completely.
And all the other ones had to update section numbers and quotes and all that.
And the big part for me was I was thinking I might spend months doing this
because I don't know which of the questions actually now have a different answer
than they had back in the day.
So I basically will have to re-review all the questions.
So when I knew I was going to be on CppCast, I thought,
hey, I have to prepare a way for the community to help
so I can ask people for help while I'm here.
But instead of doing that,
I will say that everything is now ported
to CppCast 17
because within a few hours,
people started contributing.
Wow.
And Simon Brand, who was here a few weeks ago,
he ported some questions.
And Niklas Lesser from Germany,
he ported like 90 and uh nicholas leso from germany he ported uh like 90 questions
over the weekend uh yeah it was i was thinking i would spend months but it took four days because
mostly of nicholas leso and also simon brand and i i had time to port maybe seven questions myself
before they were just finished with everything.
So I was just amazed by the effort.
Yeah, that's a great community effort.
Yeah.
So one of the things that I really appreciate about CBP references,
how you can see whether something was pre-C++11,
11, 14, 17, 20, whatever that's tagged on there.
Have you considered leaving around the C++11 versions of the questions
so that if someone is on C++11 in their actual daily work,
they could say, I want to see the C++11 version
and then show me how it's changed or something like that?
And that would actually be fun.
Turns out it's only a few questions that actually changed.
Okay.
The explanation for the answer being correct
is sometimes in a completely different part of the standard
than it used to be.
Right.
So like the one I mentioned with decal type
on a captured variable that isn't ODR used,
it should act as if it was ODR used.
That's now... It used to be in the lambda thing, and should act as if it was ODR used. That's now...
It used to be in the lambda thing, and now it's in the
decl type thing. Things move around, and it's...
But it hasn't really
changed that much. So I'm
not sure if it's worth the effort.
But it's mostly just
the quotes are different, and the section
numbers are different.
We also had someone suggest
we could just leave the questions
for C++ 11 and then use C++
17 for the new questions.
And then it says, like, this question is for
11, this one is for 17.
But I think that would be more confusing.
So it was better to make the effort
and port everything, and
especially when Niklas and Simon
did all the work.
Yeah, it was very much.
I think I spent more time preparing for setting it up for the community
to help than actually I spent doing any of the actual work myself.
So most of the time that I put into it was just making scripts
to export everything to a Git repo so that people could make full requests
and writing readmes and making sure that everything was easy for contributors.
And it looks like that paid off at least.
That's great.
Do you have any plans to update the site
now that everything's in C++ 17?
Just publish more questions.
Try to get more questions that are simple.
Not entirely trivial, but simpler,
so that we can have some filtering.
So it's easier for people who aren't compiler implementers
to actually get more questions right.
Because I think it's too hard for most people.
So I think that's the main plan.
The patron suggestion you had, I might do that.
And also maybe trying to find some way to have other moderators than only myself.
Both to help moderate other people's questions, but also to have someone review my own before I publish them.
And have Twitter review them afterwards afterwards as it happens now.
I have a feature suggestion.
Maybe have a
way to open up Compiler Explorer
from CppQuiz to see the
answer work in a compiler.
Yeah, that's
a good idea. I wonder if I added
an issue for that, actually, or if I didn't do it yet.
If not, I'll do that later.
Just some way of going directly to...
No, that was for my blog.
I didn't think about it for a few weeks.
But yeah, that's a good idea.
Unless you consider it cheating, then.
Well, you could do it once you've answered the right answer,
or say you give up.
Well, one thing we haven't discussed
is you actually have hint
levels right uh yes so you could potentially have a like on the second level hint here's
go go play with this in the compiler or something like that yeah yeah that's that that's a good idea
as well actually writing the hints is one of the most difficult things because it's not that often
it's not very there's not a lot of things going on it's i try to always keep it to like there's one thing going on in each question
so there might be some like surrounding stuff but there's it there's every question is supposed to
only ask about one one specific thing and it's really hard to give a hint many many times about
the thing without giving it away um So at this point, do you have
reasonable hints for all the questions?
Yeah, all questions have hints.
I think they're pretty okay.
Often when I get contributors
contributing questions, they say
they fill in for the hint field. They just say,
sorry, I couldn't think of a hint.
And I completely understand because
it can be hard to give a hint without giving everything away right because often it's if often it will be
think about this very very specific thing how does that work to like draw your attention to
what the question is really about rather than really helping you that much. But, yeah.
Do you have any favorite question,
either user-contributed or one you came up with on your own?
My favorite questions are the ones where people have got it correct when they contribute something,
and where they have put in references to the standard.
Because often it's like, here's an explanation of what's going on.
And I have to figure out, is that actually what's going on?
Or is it what they think is going on?
So I often spend a lot of time.
I spend some time in the standard and a lot of time also on CPP reference and Stack Overflow.
That's actually one tip I could give for people who try to figure out how things really go on.
Don't always start reading the standard in the beginning.
First go to Stack Overflow, go to CpReference, so you get some idea of things.
And then you know better what to look for in the standard,
because it's really hard to read the standard very often.
But yeah, so favorite questions.
If they're correct, they're referring to the standard and
it's not too esoteric and and you can learn something useful about the language maybe that
exact question isn't that useful it's about the conditional operator.
So if you have an int i, and then you have a conditional operator saying, if i is larger than zero, the result is i, otherwise it's one.
So the result can either be i. Otherwise, it's 1.
So the result can either be i itself or it can be a literal.
And then you bind a reference to the result of the conditional operator.
Okay.
So we have a reference that either is bound to i itself or to a literal.
And then the question is, is that reference actually bound to i when i is the result of the conditional operator?
And the thing is, because then you get to think about,
does it need to make a temporary?
And you can talk a bit about the difference between a reference and a value.
Because the thing is that the conditional operator
either returns i itself or a literal so you can't
actually refer you can't return a reference because if it is the literal that's the answer
then that literal will go out to scope so you can't find a reference to that but you can find
a reference a const reference to a literal uh yeah but but you have to return something from
the conditional expression itself and that's in this, has to be actually a PR value.
Okay.
Yeah, so it's a bit hard to explain code without looking at code, I think.
But it's a very, very simple question.
There are four lines in main, and that's it.
And you get to think a little bit about types
and what can you bind references to and not.
And, yeah, it's a const reference you bind,
but you have to
make a PR value. It's sort of
like also the post
and pre-increment operators
where one of them has to make a copy because
it has to actually be able to return the value as it
was before you incremented
and things like that
that seems like a corner case but it gets you thinking
a bit about how does the language actually work
Right
Yeah so I like those That seems like a corner case, but it gets you thinking a bit about how does the language actually work. Right.
Yeah, so I like those.
Well, you recently blogged about one involving virtual destructors that caught my attention.
Yeah.
I guess recently.
Yeah, well, back in March, so six months ago.
Well, I guess I got the answer wrong when I started reading your blog.
I'm like, oh, of course, I know the answer to that. So, would you mind describing this particular one to the listeners?
Yeah.
I'll just bring the code up here.
So, the thing is, if you have a base class and a derived class,
and you delete, so you have an instance of the derived class, and then you delete it through a pointer to a base class and a derived class, and you delete...
So you have an instance of the derived class,
and then you delete it through a pointer to the base class,
and you don't have a virtual destructor, what happens?
So the person who submitted the question said that,
okay, if you delete a derived class by a pointer to the base class,
and the destructor isn't virtual, it's only
going to destroy the base part of the
object and not the derived part.
And I think that's probably
what everyone is going to see their compiler doing.
But actually, it's undefined
behavior.
So it's undefined behavior to delete
a derived class through a base class pointer
if the destructor isn't virtual.
And, yeah.
So the person who submitted the question said
it's going to only call the destructor
for the base class object.
And I thought, yeah, that makes sense.
But then I thought, okay, I have to check.
So I went to the standard and read,
and I found, hey, it says right there
it's undefined behavior.
Yeah, I did not realize that was undefined behavior yeah i did not realize
that was undefined behavior i thought it was defined that it would just delete the base part
yeah it says uh if the static type of the object to be deleted is different from its dynamic type
the static type shall be a base class of the dynamic type and the static type shall have a
virtual destructor or the behavior is undefined and as far as i know no
compiler will warn on that unless you have some other virtual function to create a v table in
the first place and then it'll warn that you didn't provide a virtual destructor yeah yeah i
i don't i don't know actually but uh yeah it's it's a very good example of a thing that sounds right, and it's not.
So yeah, that's why this one was interesting, I think.
And if I recall, your comment in your blog posting made a lot of sense.
It's like, how can we reason about an object that wasn't properly destroyed?
Yeah.
So if you say that, okay, this is actually a well-defined
behavior, if you delete it without a virtual
destructor, it will only destroy the base part
of the object. How can
you do that without leaving
a lot of other stuff undefined? So what happens
with the stuff in the right class? What happens to
the memory? What happens to their destructors?
What happens
that should go out of scope? What happens
with the RAI things you try to do in that class and so i think you could you could say that okay
that's defined but after that then it's undefined something something more undefined is going to
happen for sure but the thing of course with the ub is that if it if it happens at one point then
the entire execution of your program is, is undefined.
So if your program is running for two hours and then you get undefined behavior,
then everything up to that was actually undefined behavior.
Right.
Uh,
so it wouldn't really make sense to,
to try to define this scenario.
And,
uh,
yeah,
that's one of the scary things about C++ as well.
That's like,
if everything is fine up until a point and then then it's not
fine then by definition everything up until that was not fine either and that's of course to be
able to allow the compiler to do crazy optimizations but it's yeah it's scary stuff
yeah the standard makes no guarantee about uh the result of the program including things that
preceded the undefined behavior.
Something like that is the wording, yeah.
Yeah, so that's why I don't
think it would make sense to try to define this
at all.
Right.
Okay, well, is there anything
else you wanted to go over before we let you go,
Anders?
Well, yeah, actually,
one thing I would say
is that since I've
now been looking for a job in Oslo
for a few months, I would just say
if you need an interesting C++ job,
Oslo is great. I went to
so many really cool places,
people making really, really fancy stuff.
I was really surprised
about how much cool is going on in Oslo.
So, yeah, we have Cisco making all their video conferencing
stuff in Oslo
they have
a lot of fun it seems and include
OS the C++
Unikernel is made here
I didn't realize that
so I went talking to those guys as well, really cool people
very very smart
and yeah Vivaldi is being made here So I went talking to those guys as well. Really cool people. Very, very smart.
And yeah, Vivaldi is being made here.
Hudley, which is now the official Google Hangouts hardware camera,
is being made here.
Yeah.
And of course, the oil and gas industry in Norway has lots of really crazy tech stuff.
So yeah, Oslo is really cool.
And my new company, S civet where i will start in
first of october we make uh machine vision stuff so it's uh they made the like the world's most
accurate 3d color camera wow so it's pretty pretty cool and uh what i found really interesting was
they're making hardware so they're making eyes for robots basically
and so they made like the best hardware
and they said that's only half of what will get us to be the best
the other half is equally important, it's having the best API
and I think that's kind of rare for a hardware company to say
that the API is going to be just as important as the hardware
to give us a business advantage.
And
that was really one of the things that
really sold me about that company. It seems
like a very interesting focus to have.
And yeah, there's
a lot of embedded stuff going on in Oslo, and we talk to
embedded people, they're always like, oh, the stuff I get
from the hardware company is so shit.
And we're...
So yeah, someone, really making an effort
to make a great API for hardware, I think.
It seems to be uncommon, I think.
That does sound interesting.
Yeah, lots of cool stuff going on in Oslo.
And the C++ community here has been kind of dead
for several years, but Patricia,
that we talked about earlier, she's released
bringing it back up again,
and I plan to help out with that as well.
I think we're going to
see the community
be a lot more active going forward.
Awesome.
Are you planning to attend any
of the upcoming conferences we've talked about?
No.
Currently, I
don't have a job
because my new job doesn't start until in a few weeks.
My previous job wasn't in C++,
so I've been away from everything.
But I hope to go to more conferences.
I gave a talk at a little NDC Tech Town conference.
It was a few hundred people a few weeks ago.
But I definitely hope to go to one of the bigger ones uh soon i guess on that note we
should mention that you are running out of time very quickly to buy tickets to pacific plus plus
also which is coming up here in october and as we all know cbp con is coming up at the
end of september one week after this airs, basically.
Would it be okay to say that we're hiring at Civid?
Sure.
Sure, why not? You already did.
If you're good with C++, or if you are good with machine vision, or we also need people with machine learning and AI stuff.
So it seems like a really cool place to work.
I haven't started there, so I can't make any guarantees,
but it sounds great.
Lots of cool people.
And also Sickle, that you had an episode about a few weeks ago
with Simon Brand.
Yes.
If anyone knows Sickle or wants to learn it,
we're having some efforts in that direction as well.
So, yeah.
Awesome. Very cool, yeah. Awesome.
Very cool, yeah.
Okay, well, I'm very glad that you're getting back to be a full-time C++ developer
again, and it's been great having you on the show today.
Yeah, it's really fun to be here. I'm
just so glad to be back with C++, like, with the
community and everything. It's, yeah,
I just really feel like
I'm back in the right place. Oh, welcome back.
Thank you.
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 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