Text Broadcast of CppCast 277: Virtual Teaching and Plenary
- intmax_t in C and C++
- CLion 2020.3
- Virtual ISO Plenary
- Teaching During COVID
- CppCon Talks
- C++ in Game Development
Episode 277 of CppCast was recorded on December 8-th, 2020. Hosts Rob Irving and Jason Turner talked to Patrice Roy about intmax_t in C and C++, Lexy, CLion 2020.3, teaching C++ during COVID and the first ISO Virtual Plenary.
The sponsor of this episode of CppCast is the PVS-Studio team. The team promotes regular usage of static code analysis and the PVS-Studio static analysis tool.
Rob: Welcome to episode 277 of CppCast. At the top of every episode we highlight a piece of feedback. Last week we had Robert Leahy on the show and we were talking all about Networking TS.
So we got a couple of comments on Reddit. This one was from Xaxxon, " I wish the C++ language would focus on things that cannot be done based on the limitations of the languages instead of looking at things which have perfectly good implementations on all necessary platforms. Graphics, networking, etc (not sure what else but at least those two) are solved problems. Static reflection, however, is not. True language features that enable new constructs should be what is added to the language. Everything else can go into boost or some cpp-iso-official boost-like library. While there may be different people focusing on different parts of the language, I can't imagine that there's not some overlap and stress coming from core language people thinking about feature additions." (Link to Reddit)
Do you have any particular thoughts or comments on something like networking being standardized though, Patrice?
Patrice Roy: I've been on cpp.chat in a debate on that topic. My point is always the same. I want standardized networking because I'm so tired of using the CAPI and doing reinterpret_cast and fiddling. If I had at least the basics, that would let me move away from the platform headers, I'd be so happy. So I'm moving for standardized as well.
Jason: I've used either some libcURL wrapper or Qt or Boost.Asio since probably, say 2005. It was only before that, that I would bother going down to the CAPI.
And after that I used whatever library had already been pulled into the system.
Patrice Roy: See, the trap is, when you're teaching, you do not have the time to do install APIs. The students don't have the time to do that. So when you're stuck there, you're using the Unix or the Windows platform API to work, unless you can include something that's standard C++, and then you're done, but they cannot make students install boosts. I don't have the time to do that. So, but it gives me an excuse to show unions and talk about reinterpret_cast and alignment.
Jason: Yep. All of this is undefined behavior. Don't worry about it.
Rob: You can also leave us a review on iTunes or subscribe on YouTube and joining us today is Patrice Roy. Patrice has been playing with C++ either professionally, for pleasure, or for work for over 30 years.
Figure 1. Patrice Roy at the CppCon 2019 conference.
After a few years of doing R&D and working on military flight simulators, he moved on to academics and has been teaching computer sciences since 1998. Since 2005, he's been involved more specifically in helping graduate students and professionals from the fields of real-time systems and game programming develop the skills they need to face today's challenges.
The rapid evolution of C++ in recent years has made his job even more enjoyable. He's been a participating member in the ISO committee since late 2014 and has been involved with the ISO programming language vulnerabilities since 2015. He has five kids and his wife ensures their house is home to a continuously changing number of cats, dogs, and other animals.
intmax_t in C and C++
Rob: Patrice, 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 lately. So this first article is on JeanHeyd Meneide's blog, and this is "A Special Kind of Hell - intmax_t in C and C++".
Figure 2. JeanHeyd Meneide delivers his talk on Unicode for C++23 at CppCon 2019.
We've talked about ABI breakages fairly often over the past year or two, but this goes into the ABI breakage situation in C, which is apparently much, much worse than, in C++.
Patrice Roy: According to JeanHeyd, it's unfixable in C and it might just be the case with the principles that he has - but it's very tough to fix in C++. What I liked is that he pointed out that we had the same problem in a sense with size_t and other such types in there. So I recommend that article. Great work. Well-written. Very clear.
Jason: There's at least a tiny bit of hope since in C++, at least in the APIs that are part of the C++ standard library, not part of the C standard library, we can use overloads. And then that's encoded into the name mangling where mangling just amplifies this problem.
Patrice Roy: Yeah. Well, you have macros, as he said, I'm a fan of exposing your internal names as types in your classes, like size type and value type, I I'm okay with that. Cause it lets client code evolve properly. But these things bring a special kind of hell to us in the way they are used and defined.
Jason: I would just say also for the record, I didn't even realize intmax_t was a thing. I thought that I knew all the standard types or typedefs.
Patrice Roy: Oh, nice. One of the things that make people tremble when you go to standards meeting, nobody wants to touch that slide monitor at all, or there's a few others like that they just carry.
Jason: Is there also an intmin_t for a char typedef?
Patrice Roy: No, because you cannot go lower than a byte. It's the upper bound that's the problem.
Rob: All right. The next thing we have here is a library. This is a new one from Jonathan Muller.
And it is called Lexy, a Parser Combinator library for C++ 17. It looks like it's pretty powerful with being able to specify a new DSL.
Patrice Roy: I just looked at it this morning, I liked the technique and the approaches I'm looking forward to.
Sometimes you look at something and it's the idea that's important. When I looked at it for the first time I liked the syntax, I liked the way it expressed the idea. That's a pretty powerful way of naming things. So when I looked at Jonathan's library this morning, quickly, I liked the approach. There's something inspiring there.
So thank you, Jonathan, for that. That's pretty cool. I haven't played with it though, so I don't know how good it is in practice. But it's inspiring work.
Jason: It's for our listeners. If you want to get an idea for something that's pretty, relatively complex, use the Json parser that is in the examples folder.
If you remove the test code, it's only 272 lines. Which is a pretty terse succinct Json parser.
Patrice Roy: I've seen one by Louis Dionne at a meeting once that was scary small.
Jason: I've also seen small ones, but to be fair, the small ones that I've seen weren't necessarily tested for compliance.
And Lexy actually does claim to be at least fully compliant. I don't know about Louise of course.
Patrice Roy: The separation between the rules thing and the way the values are being defined - there's really something cool. I urge our listeners to take a look at it, if only for the form it takes, because it might give them ideas for their own APIs.
Rob: The last thing we have is from JetBrains blog, and this is CLion 2020.3, their last release of CLion for this year.
They're advertising a lot of new features in this blog post: core dump debugging, CTest support, MISRA guideline integration.
So it looks like they put a lot in here for this final release. Jason, are you still using CLion as your IDE?
Jason: I am. You know, it is saving me a ton of time when it comes to working on large client projects, because [the IDE enables me to] quickly navigate around the code. If you know anything about me, a year ago I wouldn't have said that at all.
"I'm not like them! Who needs an IDE?" I upgraded to 2020.3 before I started my current task. And didn't even realize that I was now able to drag the little arrow around inside the debugger.
Rob: Yeah, that's nice. I know this feature has been there in Visual Studio for a while, but it's nice to see it in the CLion IDE as well now.
Patrice Roy: I haven't played with it much myself. But the way MISRA rules are being shown or suggested is interesting. It's a nice way to present things.
Rob: Yeah. And if you're interested in learning more about what's new in CLion 2020 0.3, our friend of the show Phil Nash shows off a lot of these new features in his little videos.
Virtual ISO Plenary
Rob: Okay. So Patrice, it's been a while since we had you on, and one of the first things I wanted to ask about was the recent virtual ISO plenary and how the things went.
Patrice Roy: Yeah, it was quite interesting. We had planned a few hours and it, it took much less than what we had planned.
There was almost nothing controversial. Normally there are a lot of discussions, and in this case the only one was the suffix for size_t. There were some votes against it, but it was a majority vote.
The big thing was discussing our code of conduct - how we can make the community more inclusive, how we deal with each other with all the online meetings all the time, because it's harder to make humor, snickering, remarks. So there was a presentation on that and discussions.
Cudos to Davis Herring who wrote a huge paper in core that described many things that are being done, particularly, if I remember, the overload resolution rules, which are very complex. So they just did a tremendous piece of work.
Jason: And normally there's one of these plenaries at the end of each in-person standards meeting, right?
Patrice Roy: There're essentially two plenaries - one at the beginning and one at the end of the meetings.
At the beginning of the meetings where we set the rules for the week, discuss room assignments, remind people of the code of conduct. We take some administrative steps and plan the evening sessions because we normally have evening sessions on top of the day sessions.
Then we meet at the end for a plenary on Friday afternoon, we take votes, and then there's an administrative plenary on Saturday morning, where we close some issues with some isolated voters.
Jason: So is this the first closing plenary that you've had this year with all of the cancellations and in-person meetings?
Patrice Roy: There was Prague, but I couldn't go there. We had one in Bulgaria, and, if I remember, one in New York that we planned for a later time.
But there were a lot of virtual meetings. You should see my email inbox - it's crazy. If I did every one of them, I would be in a meeting every day.
And that's one of the things we've discussed - there's meeting fatigue in people. People have day jobs and it's volunteer work to come to these. On the other hand, it makes, the language evolve and advance, so they just need to find the right equilibrium there.
Teaching During COVID
Jason: I have heard that from a lot of people about meeting fatigue, Zoom fatigue, and stuff. It's interesting because with my meetup, a lot of my regulars stopped coming to my meetup because it's virtual, but an entirely different group from all around the country and the world is coming to my meetup and taking advantage of the situation.
Patrice Roy: Probably depends on what you do during the day. I mean, if you can do normal coding, that's cool. I give classes, so I'm on Zoom seven to 12 hours per day.
Jason: Oh wow.
Patrice Roy: It's significant. The students that I have are tired and isolated, they're starting to suffer from depression, anxiety. I'm trying to make them work as a team, talk to people and everything. So Zoom fatigue is not Zoom. It's the fact that you're not really linked to people anymore.
Jason: Wow. So, I mean, since you brought it back around to school, how many classes are you teaching right now?
Patrice Roy: Two at the university, and I have three groups in college. Third semester, fifth semester students, and then master degree students. There are a lot of French students. So I'm giving classes on Friday morning at French times. So for me, it's seven in the morning.
Most of my students in general, I don't even know what their face is because they're not forced to open their cameras. I know their names, but it's a very strange experience. I'm trying to make it engaging, to put some more time aside, speak to people and discuss their work, because it's more human.
Jason: So I just have a hard time accepting that you've been teaching a class a whole semester and not even know what someone's face looks like.
I think at some point I would just crack if I were you as the instructor: "Turn on your camera!"
Patrice Roy: No, we can't force that because you have the right to control your own image. I I'm trying to get them to do that for the exam and trying to make it fun. Let's make it cool, everyone, just at least for one session, for one period, so that you can see your faces and know who you are learning with.
And I can supervise better what they're doing if I do that too, but I cannot force them.
Jason: So are these classes just like normal university classes you meet for an hour, hour and a half, three days a week or something like that?
Patrice Roy: It's like this, but three hours in a row. We're together for three hours in a row. And we do work, they see my stream, I write code with them, we discuss things. I do the same thing I do normally, but not really - [when] I'm in the room with them, I speak loudly and I hit on tables and [now] I can not speak loudly because they have me in their ears.
I used to do that when I gave talks and I stopped because I knew two people were complaining: "My ears!". So I don't do that.
Patrice Roy: When the French students come to Quebec in January, we are going to put them in a big room, spread them out and ventilate the place properly and take care of them.
I had one class in person during a semester. It was a very tiny master's degree class with two students. I could go there physically and speak. It was awesome. And after mid-semester one of them hurt his back, and the other one got COVID, so we moved to remote classes for the second part of the semester.
Jason: If I understand, UK is getting ready to roll out some vaccines next year.
Patrice Roy: They actually did! Someone got a vaccine yesterday.
Jason: Okay. Now, since you're involved in university and college curriculums and stuff, is there a discussion about what that looks like from the university perspective?
Does anyone have a plan saying, okay, we start getting vaccines rolled out, then we will do X? Or?
Patrice Roy: Well, we don't decide, in Quebec at least it's a governmental matter. This fall at Sherbrooke university, where I give my classes they had rented office space outside of the university to get more room and spread people more. The classes are given in churches, because there's space there.
Jason: You're right.
Patrice Roy: And the good main thing is the actual in presence experience for two thirds of the semester, they had to stop at some point because there was an outbreak in the area there. And my understanding is that the exams are being done in person too right now.
What we maintained was the classes that require presence. So when you need the nuclear devices or things that would explode in your house or when you're putting needles in the arms of animals or people.
My classes are all remote because I don't put needles in anyone. I have classes with robots and stuff. So these will require some in presence work during the winter.
Rob: Since you're talking about some of the difficulties with teaching over the past few months, have there been any things you've found that have been nice with teaching this way?
Patrice Roy: Well, I use less gas. I'm quite late on my podcasts. I normally am. I'm pretty much up to date with CppCast among others. And now in at least five podcasts I'm like 20 episodes late. What's nice, the tools are holding up. That's my biggest surprise. It's cool that Zoom, Teams and stuff, they've all held up.
Sharing documents has proven to be a functional thing. Seeing students' screens works. Those who are mature enough, they ask questions, that works too. Discord rooms work.
People trade ideas and stuff and they help each other. So yeah, we can, we can make it work. It's not pleasant, but it works. So I'm happy about that. The worst part is grading. So reading the assignments that they do with the papers, grading, that takes forever. What I mean forever, I mean five times as much time as it normally does.
And why is that? It's because you don't see them. So you cannot present some things, just circle something in red and say, come speak with me and be face to face and explain things. You have to put things in words. So you have to bring context and you have to be careful because they're depressed on the other end.
You don't see them. You don't know in what state they are. So you have to make sure that they will get the gist in a constructive manner. That really takes a lot of time. When you have a 54% class C. Takes like weeks and weeks and weeks on end, just to grade one assignment. So I'm so late in my grading.
Jason: Did you use at all any of these automated grading systems where the student uploads the program and if it gets the correct output, then they pass or fail?
Patrice Roy: No, I'm against that. It's fine for one part of the job, but it doesn't tell you if they wrote good code.
I try to do self-correcting exams for the execution part of things. So, if I can, I'll make sure I can autograde the execution part, but I'll still look at the code in that takes forever.
Rob: I wonder off the discussion for just a moment to bring a word from our sponsor PVS-Studio. The company develops the PVS-Studio static code analyzer, designed to detect errors in code of programs written in C, C++, C# and Java. The tool's a paid B2B solution, but there are various options for its free licensing: for developers of open projects, Microsoft MVPs, students, and others. The analyzer is actively developing. New diagnostics appear regularly along with expanding integration opportunities. As an example, PVS-Studio has recently posted an article on their site, covering the analysis of pull requests in Azure DevOps, using self-hosted agents. Check out the link to the article in the podcast description.
So, Patrice, I think you gave two talks at CppCon 2020 this year? Do you want to tell us a little bit about your "Things That C++ Does Right" talk?
Still, I see a number of things that other languages do, and I keep seeing people complaining about C++ all the time saying, "Oh, this is so bad. Not type safe, not memory safe, blah, blah, blah, blah, blah." Which of course there are bad things in every language. But I do know things that C++ does really well.
If you put a default value in a member variable and then your constructor passes and does something else, there will be only one initialization, not two. If you do C#, you're going to get two initializations for the same variable if you do that.
There is a number of interesting things that we do that are pretty cool.
I tried to put a list of these things that I noticed that we do right, in that talk.
I also had another talk on things that I called "Void print functions and other innocuous evils". So I had this dark talk on things that are wrong, and this bright talk on things we do right.
I gave the "Things That C++ Does Right" talk to the user group in Montreal, but there were people from Toronto and Vancouver. I could see a number of friends that I see in conferences, in committee meetings there.
And they were quite a bright and big audience, a lot of discussions afterwards, people reacted nicely to it. I was pleasantly surprised.
I hope people liked it. Some people saw code samples on YouTube after that and said, well, that's that not C# code. I know, that's the point. It's not that C# is a bad language, but you can do that, with it and it's kind of weird.
So you have a string s that equals null. And then you add null and check its length and it's zero because again, if you had null to a null string, you get an empty string. That's weird to me.
Jason: That's weird, yeah.
Patrice Roy: But it passes, it's fine. Maybe it's good for some mindset, but I like my strings to be values. So yeah, value semantics are awesome.
Patrice Roy: But we can craft that in C++ too, because we're crafty people.
Jason: Any other specific examples that you thought were worth mentioning from that talk, about things we do right in C++.
Patrice Roy: The big point really was that we have a language that lets us be efficient.
There're things that we can write elegantly in C++ if you understand how containers and iterators work, that are difficult to write in other languages, but they provide functions that do it for you. If you had to do it yourself, you'd be in trouble. So we have very good groundwork tools to build nice things from clean abstractions.
One of the examples that I had in my talk was a "Read All Text" or something. In C#, if you want to read all the text from a file, you need a function that does that for you. If you have to read it yourself, it's involved.
In C++ it's a one-liner because we can use a pair of iterators on your string and build a string from it - and you're done. And in the same way you can copy containers. You don't need to have two arrays or two lists to do it for you. You ask constructors that do the job. It's a very general solution to the problem.
It works, it's efficient, it's clean. So, it's okay also to have a big library with special case tools that work. That's not bad. But I appreciate that in C++ that's not the way we went.
Patrice Roy: Think about Lambda captures. When we write Lambdas, we express precisely what we want to capture and if it's by value or by reference. If you're writing a Lambda in C #, you write less code, but if you want to do something else than a reference to something, you need to use a variable in the enclosing scope, make a copy of it, and then use that copy inside your Lambda.
Otherwise, you'd be referring to something you might not be looking for. So if you're doing a for-loop that starts threads, and capture the index variable of your for-loop, you're going to be in trouble in your Lambda, because you're referenced by default. But if in your for-loop, you make a local copy of the thing, then you capture the local copy and it's a different variable for every iteration of the loop.
It's not bad. But to me, it's weird. So I appreciate that we can be clean and clearly express our ideas in C++.
Patrice Roy: Nothing about this is perfect at all. It has lots of words and that's fine, all languages do, but it's reviled by some, and I think it's unfair. I think it's a beautiful language.
C++ in Game Development
Jason: Well, before we were getting ready for the show today, you mentioned that you were working on a set of requests for SG 14, which is a committee or subgroup working on game development and high-performance features. Do you want to tell us a little bit about that?
Patrice Roy: Absolutely, Lloyd and C group. I was approached by one of the big game companies in Montreal in 2019, because, they said, well, it's time that they tell the standards people what they want and what they need. And I really appreciate that of them. They came with a list, we went to a cafe, we chatted for about an hour, and did a number of ping-pong emails to make the list more formal, clearer. And then I started going to other companies and I'm building written list of things that the companies would appreciate from the language: some library stuff, some core language stuff. I think it's a reasonable list and some things in there will go in the direction that the language is already going.
So I'm trying to prepare the presentation to get a maximum support from first SG 14 and then the rest of the committee. I think it can be something that will bring people together. It's a good list. There is, astonishingly to me, a number of non-performance-related things there, things about safety, integer overflow, better diagnostics.
I have around 32 requests right now I'll try to categorize and bring to the SG 14 in order to make C++ closer to what the low-latency people need. So I'm hoping to do that early 2021.
I met two big companies so far, spent three to four hours in both cases and, I think it will appeal to a lot of people. It's nice to see niche communities. They're trying to make the language better, but in a way that will benefit everyone.
Jason: Are there any standout things that you would like to call attention to?
Patrice Roy: Well, the trend towards compile-time programming continues. There are things that people like in C# that they would like C++ to do, like compile time string formatting.
I think we can do that really. The string interpolation that C# does would, I think, benefit a lot of people, if we could find a way to make it work in C++, and we probably can.
Jason: I'm curious, since you mentioned integer overflow or signed integer overflow, if they have the capability of testing their games with UBSan enabled to see where it catches these things, if that's interesting to you and developers.
Patrice Roy: Yeah, they could, but what I heard was, some of them would like unsigned integer overflow to be considered UB with some compiler options in order to detect it better with such tools. So some of them would like that in some cases to be considered as UB to detect it more easily.
That surprised me, but I heard it from two different companies. There is a need for that somewhere. I have use cases that they suggested.
Rob: Is there anything else you wanted to go over today, Patrice, before we let you go?
Patrice Roy: Oh, you know, what can I say? I miss listening to CppCast. I miss meeting the committee people. I can tell you that one of the highlights of the last meeting to me was that Mr. Brown, Walter Brown, told us he would be retiring. He's a bright mind, very focused. His CppCon talk this year to me was the best one we had. It was tied to how we find things through EDL and other mechanisms. Also, let me say that I miss Mr. [Beman] Dawes who just died last week.
He's someone I met at CppCon and had the pleasure of working with in a few meetings. He had a keen mind. He was gracious to me. And I appreciate him very much.
Jason: Okay. Well, it was great having you on the show again today, Patrice. Thanks.
Rob: 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 firstname.lastname@example.org. We'd also appreciate it if you can like CppCast on Facebook and follow CppCast on Twitter. You can also follow me at robwirving 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 and you can do so at https://www.patreon.com/CppCast. And, of course, you can find all that info in the show notes on the podcast website at cppcast.com. The music for this episode was provided by podcastthemes.com.
- PVS-Studio. Write #cppcast in the message field on the download page and get one month license
- PVS-Studio: analyzing pull requests in Azure DevOps using self-hosted agents
- Why it is important to apply static analysis for open libraries that you add to your project