CppCast - The Old New Thing
Episode Date: March 5, 2021Rob and Jason are joined by Raymond Chen from Microsoft. They first talk about Herb Sutter's virtual ISO Plenary Trip Report and some new features voted into the C++23 draft. Then they talk to Raymond... Chen from Microsoft about his career working on Windows and the Old New Thing blog. News Trip report: Winter 2021 ISO C++ standards meeting (virtual) Learn C++, Qt and QML the easy way Links Raymond’s blog The Old New Thing. Here’s the post that made his July 4 family picnic a little more stressful Raymond is managing editor of the Windows Universal Samples and the Windows Classic Samples repos on GitHub. Here’s a YouTube playlist of Raymond’s One Dev Minute short videos. Raymond can be found on GitHub as @oldnewthing, and his necktie’s Twitter account is @ChenCravat. Sponsors Visual Assist
Transcript
Discussion (0)
Episode 289 of CppCast with guest Raymond Chen recorded March 3rd, 2021.
This episode of CppCast is sponsored by Visual Assist, the well-known productivity extensions
for Visual Studio. Visual Assist speeds up development with features like smart navigation,
code inspection and suggestions, powerful refactoring commands, and a whole lot more,
even spell checking and comments. Start your free trial at wholetomato.com.
In this episode, we discuss another virtual ISO meeting.
Then we talk to Raymond Chen from Microsoft.
Raymond talks to us about working on Windows
and the old new thing blog. Welcome to episode 289 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?
I'm all right, Rob. How are you doing?
Doing okay. Keeping very, very busy.
I don't want to go into too much detail, but yeah, been really busy doing a lot of projects around the house.
How about you? What have you been up to?
Just normal contract-y kinds of things and took some vacation time this past week that's cool
very nice okay well at the top of every episode i treated a piece of feedback uh we got this tweet
from bjorn faller saying after having listened to cpp cast with uh nicole i will henceforth refer to uh victor zverevich's
format library as fount it was also a very interesting episode thanks i think i pronounced
that the same way nicole did right fount fount yeah fount i think that's um i had to completely
forgotten about that until just now seeing bjorn's tweet that was uh i don't know if i can bring
myself to do it, Rob.
Yeah, I think I'm probably going to keep saying format,
but foompt is very fun to say.
It is.
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 cppcast.com.
And don't forget to leave us a review on iTunes
or subscribe on YouTube.
Joining us today is raymond
shen raymond has been involved in the evolution of windows for more than 25 years in 2003 he began
a website known as the old new thing which has grown in popularity far beyond his wildest
imagination a development which still gives him the heebie-jeebies the website spawned a book
coincidentally also titled the old new thing he currently appears regularly on msgn channel 9's One Dev Minute channel in the One Dev Question video series. Raymond, welcome to the show.
Hi, guys. The One Dev Minute thing, I guess, has been on hold since nobody can go to my office and
film. But hopefully that'll come back once we're all allowed to go back to the office again.
You know, I saw this since 2003 for the old new thing.
And I was like, was it really only 2003?
Like I swore it was before that.
But then if I put in my internal calendar, I'm like, oh yeah,
that's approximately right when I first started doing C++ full-time
professionally.
So then it adds up because I thought of the old new thing as always having
been there as long as I've been a C++ developer.
And I guess that's pretty much true. I barely made it. Barely made it. I think that's like six months after I
became a professional C++ developer or something like that. Yeah. And you know, the first six
months you don't remember there's too much going on. Right. By the time your brain started forming
memories of C++. Okay. Well, Raymond, we got a couple news articles to discuss.
Feel free to comment on these, and then we'll start talking more about what you do at Microsoft, about your blog, and everything else.
Okay?
Sure.
Okay.
So this first one, we have a trip report from Herb Sutter.
This is the Winter 2021 ISO C++ Standards Meeting.
Of course, another virtual one and although it is a virtual
meeting uh they voted some more papers into c++ 23 uh we got a little handful of feature
descriptions here um any of these uh either of you want to talk about in a little more detail
so there was the the the fact that the empty parens after the lambda brackets were optional
only in certain cases.
Like I personally found that quite frustrating
because I would leave them out
and then I would get an error
and be like, ah, I got to put it back in.
So it's a very small thing,
but it removes just one of many things
that made me frustrated.
And it turns out there are a lot of things
that make me frustrated,
but taking one away helps.
It reminds me, like, you know,
this is a post from Herb Sutter.
I have a Herb Sutter story.
Okay.
Many years ago, I was stupid
and actually had my work email delivered to my phone.
I have since remedied that situation.
So there's no work anything on my phone anymore.
But at the time, so it was the fourth
of july i was having a nice picnic with my family it's like yay fourth of july and then boom piece
of email from herb center telling me oh uh he and uh stephan lauade the stl both agree that my
recent blog post was wrong and so this is this is this this is really not a piece of email that you want to get while you're enjoying a nice picnic with your family.
So it's like, okay, cool, I got an email from her son.
Not so cool, he's telling me I suck.
It's like getting called to the principal's office and when you get there, you find that not only is the principal there, but the vice principal is also there.
And they're not giving you an award. They you you need to do something and it's like i find it very funny that it's nothing to do with like necessarily your job like they're not
commenting on some commit you put into you know they're you know into code the repository no
they're just commenting on your blog post. That's funny.
Yeah, well, because it says like, oh, yeah, over on our mailing list over here,
people are really talking about and we all agree you're wrong. And somehow I managed to reply from my phone trying to remain calm, project calm. And after a few emails back and forth, I was able to
convince them that I was right after all so so it sort of went it went
from one end of this scale to the other right it was like oh my oh my goodness herb sutter's mad at
me he thinks i'm an idiot too haha i'm smarter than herb sutter so but you also just lost your
entire fourth of july during that process well no that it it it would you know yeah there was there
was a there was a period of about an hour and a half where my brain was going like, oh my god, is my life over type of thing.
But then you come out the other side.
It didn't kill me, so it must have made me stronger.
But you now have to tell us what blog post this was.
What was the post on?
Oh, I'll put a link to it in the notes.
Okay.
It was about the function, like the string safety, safe string copying function.
And the point was that people were arguing, it's like, well, if you're trying to copy the string
and it's mutating from another thread, well, that's undefined behavior. And so you're already
screwed. But the point was that the safe string copy function is careful so that even in the face of malicious mutation, it never overflows the buffer.
Oh. But you still might get an indeterminate value.
You will either get garbage, I mean, garbage that was legitimately in the string at some point, right?
If you manage to read past where he chopped it off, it's like, well, it was in the string at the time, or you crash, both of which is better than a buffer overflow. Right. You know,
to go back to Herb's article, though, this lambda fix here to make the parentheses always optional
just makes me sad in a different direction now that if you just want a lambda that returns f of x,
like in the example here,
we still have to have the return keyword there.
We need terse lambda syntax right out.
We're all asking for arrows is what we're asking for.
It's something, yeah.
I don't really have a preference,
just some way to make it terse.
I mean, C Sharp and JavaScript both picked up arrow notation
for really short lambdas. Right. We'll see. to make it I mean like you know because c-sharp and javascript both picked up arrow notation for
really short lambdas right we'll see maybe maybe in you know some other the the thing is somebody
has to sit down spec it out and like convince themselves that it didn't break something
that that that it didn't break something and it's actually possible like there's probably some c++
you know the language spec is like you spec is longer than the complete works of William Shakespeare.
And so there's probably some crazy corner case
that gets busted when you try this.
If I have students ask me,
why did we choose this syntax for C++ lambdas?
I say, because there was no syntax left.
Right. All the good syntax was taken.
Yeah. Okay. was no syntax left right all the good syntax was taken okay uh last the other article we have is a
post on medium and this is learn c++ cute and qml the easy way uh and this is a post from brian
cairns who apparently has been making uh cute kind of tutorial videos for for years and years uh on youtube which seemed like
that would be a great resource if you're interested in uh learning cute and uh he kind of goes through
his whole process of how he came to cute and how he is originally very scared of c++ which i thought
was a little sad and scary he said he was afraid of c++ because his first teacher uh
made him do a whole bunch of like math examples in c++ code and he just associated it with math
yeah and so he's like yeah the the person i learned it from compared it to math and so that
made it terrible i'm like no no no math is cool come on people i really want to know what that
first book was though uh that yeah because he goes on to say he threw the book in the trash, I believe, if I remember that correctly.
So we may never know.
Yeah.
It makes me wonder if it was a stepping-off book, actually.
Could be, yeah.
Anything you want to add to this, though?
I, myself, have never worked with Qt or QML.
Since I do a lot of work with app
compatibility so a lot of my exposure to software and software frameworks is debugging crashes
um so i only get to see their bad sides which is kind of sad but it's like you know it's like oh
yeah that was that app that was it was horrible it was some app that used cute and it crashed if
he had more than 256 fonts or something like that.
So, yeah.
So, unfortunately, my only exposure to Qt is debugging crashes in apps that use it.
It's got to give you definitely an interesting perspective.
I'm afraid to ask, but I do want to ask, like, have you gotten enough exposure to Qt to do that?
To be like, oh, man, they really need to change this thing in their architecture or anything?
No, I never had the time to dig into Qt and really understand how it was put together and see what could be done better.
I'm sure from all I've heard, it's a very nice library.
I've been around a really long time now, too.
Yeah.
Even longer than your blog.
Okay, well, Raymond, let's start talking more about the type of work you do at Microsoft.
Could you maybe start off by telling us how long you've been working at Microsoft?
I started as an intern in the summer of 1989. I was a senior in high school, and I hadn't heard back from my
graduate school applications. And so I was getting nervous that I might not get into graduate school.
And so I wandered down to the career office, and Microsoft just happened to be interviewing the
following week, and they had a slot open. So I signed up for it. And so it was just, it was just, you know, a coincidence, you know, like if IBM had been interviewing the following week,
my career could have turned out completely differently. So can you give us a little bit of
like snapshot perspective at 1989 at Microsoft, like was windows in development yet? Uh, DOS was
the main thing. What kind of office, you know, do like, I don't know, just like what kinds of things was Microsoft working
on then when you started? Windows 3.1 had just come out and it was starting to take the PC world
by storm, which was kind of funny because when I came in as a summer intern, I was working on OS2
2.0, but everybody was excited about Windows. And in fact, Egg summer intern, I was working on OS 2 2.0.
But everybody was excited about Windows.
And in fact, Egghead Software,
I don't know if you remember them.
I do.
They were so pleased at how much money
Windows 3.1 was making them
that they bought Dove bars for every Microsoft employee.
Dove bars.
Dove bars.
And so people were just coming through the hall saying,
thank you for making Windows 3.1. Everybody got a Dove bars. Dove bars. And so people were just coming through the hall saying, thank you for making Windows 3.1.
Everybody got a Dove bar.
And it was like, this is the OS 2 building.
But we'll take your Dove bar.
And so, yeah.
So I spent two summers interning and doing work for OS 2.
My first summer was doing, in fact, working on the MS-DOS emulation
layer in OS2 2.0. And then my second summer, I worked on OS2 1.3 printing. So I actually
went backwards, went backwards in time. And then when I came out full time, that was in 1992,
I came into the, what eventually became the Windows 95 team. And I've been working on something in Windows ever since.
So I've always stayed in the systems division.
Interesting.
And also interesting that you were working in OS too
since a lot of people, myself included,
intend to associate that more as an IBM product.
Yeah, it was a joint
project between
Microsoft and IBM, and then
there was this messy divorce, and
IBM got custody of the kids.
Right.
We don't
talk about it much.
So does that then, since
you were working on the DAW simulation layer
you said for OS 2,
you've touched pretty much every operating system that Microsoft has worked on then in some way?
I guess. I mean, I did not work on Windows 3.1.
Oh, okay.
So it was OS 2, OS 2.1, OS 2.2, and then Windows 95, and then of course over onto the NT series.
I never worked on like embedded,
never worked on Xbox. So there are some other operating systems. They're all Windows related
that I didn't get to touch. And when did you start the Old New Thing blog? Is there a story
behind that? Yeah, well, for those of you who are paying attention during the blurb,
it started in 2003. And I started because Brad Abrams, who at the time
had a very popular C Sharp blog, he basically just told me, Raymond, you should start a blog.
And I'm the sort of person who follows instructions. So I had already started writing
sort of sketches and chapters for what I thought was going to be a book on Win32 programming.
And so I just commandeered those chapters, turned them into blog entries. And that's what started
off the initial... If you scroll all the way back to the beginning of the blog, the very first thing
I dive into is a 14-part series on scroll bars. And so that... Yeah, I know. Fascinating and
riveting content. But that's the content that kickstarted the blog.
So it's nice, you know, I hit the ground with like a two-week, you know, two weeks worth of content right off the top.
And, you know, that book on Win32 programming never materialized.
I decided just like, you know what, I'll just pump short things into the blog instead.
Although the blog did eventually lead to a different book, which is basically repackaged content from the blog,
sort of organized by topic,
and then with a couple of bonus chapters thrown in.
So you said 14 chapters became two weeks of material,
if I heard that correctly.
So have you been posting every day?
Yeah, I guess two weeks, three weeks.
I've been going, there's an article
every weekday. Every weekday?
Every weekday at 7 o'clock since 2003.
Wow. Wow. That's a lot of content, yes.
Yeah, it's sort of
a monster, right? It's this monster
that you have to keep running ahead of
because I sit down, I write a bunch of stuff,
and I throw it on the queue.
And every day, the monster eats an item off of my queue.
And if the monster eats up my entire queue, he eats me.
And so it's very important that I keep feeding the monster so you always have content
ahead ready to go yeah i feel really nervous when when my backlog drops below six months
like when i'm less than six months ahead of the monster wow um yeah for a while i had it up to
18 months i had 18 18 months of cushion which is really nice nice. And then at a low point, I think it made it down to like three months,
and then I was getting really nervous.
But now I've been pushing myself.
I've really been forcing myself, and I'm up to around 11.
I've got an 11-month lead on the monster.
So I just have to keep my running shoes on, keep running ahead of the monster.
So if you ever run out of content, that's when you retire,
shut down the blog, go into obscurity? Yeah, it it's like oh yeah i don't feel like doing this anymore
it's like okay well uh it's eventually the monster will catch up to me and then i guess that's the
end of it i'm so okay i i just had an episode on on my youtube channel where i go back and i fill
in a piece that i had not yet covered before in C++.
And I had several people comment to me like, I thought you already covered this. And I'm,
and I intro to it with saying, I thought I already covered this, but I searched through
my own backlog of videos and I could never find that I had specifically covered this topic.
And I'm just thinking, if you've been publishing one a day for the last 18 19 years do you repeat yourself like
how do you keep track i i try not to i i have a vague memory of what i've done
and occasionally i will do a repeat and then somebody will call me out on it
you're like no that's not a repeat and sometimes i'll write it up and then after i'm done i'll say hang on a second and then i'll find that it was a repeat and And sometimes I'll write it up, and then after I'm done, I'll say, hang on a second.
And then I'll find that it was a repeat, and I'm like, ah, okay, is this one better than the old one?
No, it's not an improvement.
Oh, I just have to throw it away.
And sometimes I'm like, screw it.
I put too much time into this.
This is an intentional repeat.
So then you preface it.
Well, I've covered this before, but this topic needed an updating, and you push it.
Yeah, or I put it at the end.
Just like, oh, by the way, this was a repeat.
Sorry.
But I already wrote it, so what am I going to do?
I'm not going to take it back.
I put too much time into it.
If you want a refund, you can go get it at the desk over there.
Right, right.
Do you ever find yourself pointing to specific blog posts to a co-worker to help them out with a problem or anything like that?
I'd imagine it's probably a pretty good resource for yourself. That's one of the reasons why I have the
blog is so I don't have to answer the same questions over and over again. It's like, okay,
here's a problem a lot of people are having. You know, it's like, I hear it, you know,
this is like the sort of problems that I'm hearing from my colleagues. So I'm going to write up the answer and put it up where everybody can find it.
Because I'm sure if my colleagues are running into this problem, lots of other people are running into this problem.
And so I can just solve the problem for everybody.
And so in a sense, I write the blog so people will stop coming to me asking for help.
Unfortunately, sometimes it backfires what happens is that i'll i'll write in a blog entry
about like hey uh here's how you can do this you know thing with like d2d and then somebody will
send emails like hey i saw your blog entry how to do something with d2d i want to do something
else with d2d can you help me i was like no that i i can't help you that i i wrote about this thing
about d2d because i was trying to do a thing with D2D
and I figured it out, so I posted it.
If you want help with D2D,
you can always ask the D2D team over there.
They're really nice.
Sometimes you miss part of the 4th of July
because of an article you posted too, I guess.
Yeah, and so sometimes I've learned to be careful
and pay attention to what articles go out on holidays so so that so that
way you know i i won't get interrupted on my vacation like try to try to put out boring stuff
or or stuff that are non-technical stuff so like herb stutter won't care
this is hosted on microsoft's website right? Microsoft's platform. Yeah, it sort of bounces around
as the budget for the blog platform
keeps moving from one team to another.
Okay.
Do you have any...
Right now, the dev div, the developer division,
is kind enough to let me take up shop.
They let me blog out of the room under the stairs on their site.
Because their site is mostly about Visual Studio and all that C Sharp and all that stuff.
And they're like, okay, Raymond, we'll let you blog on our site because we're being nice to you.
We have the budget so
fine it kind of seems like this kind of public visibility community involvement kind of thing
is something that microsoft at least lately has been putting a lot of importance towards i feel
like you know hosting conferences and getting more information out there and whatever so i'm kind of
surprised you have to use the server under the stairs.
Yeah, it's because there used to be a central blog team
that would host anybody's blog.
But then they lost their budget.
And so everybody was told, go find budget.
And so everybody just ran around looking for somebody with budget
who'd be willing
to pay for a server for them. Do you have any idea how many people actually read the blog since you
don't directly control the server? Yeah, there's some analytics I don't look at very often. I think
it's about a thousand regular readers. Like every page gets about a thousand hits on its first day.
Some get a lot more than that.
Some get a lot more than others.
Ironically, it's always the non-technical ones
that get a lot more hits because
of course they appeal to a broader audience.
The technical ones are like,
if I'm going to go deep
on std move of std vector,
the number of people interested in that is very
different from the number of people that are interested
in, like, why does the copy dialog give
terrible estimates?
Right.
You know, one of them
you can explain to your grandma, the other one you can't.
I want to interrupt the discussion for just a
moment to bring a word from our sponsor, Visual
Assist. Visual Assist is used
by serious C++ developers across the world. It's got great code generation. Do you need to implement methods from
an interface? What about changing a pointer to a smart pointer, even an Unreal Engine smart pointer?
Adding a symbol you've typed but haven't declared? Visual Assist will do these and much more.
Plus refactorings, more powerful than the ones included in Visual C++. Or detecting errors in
code and suggesting useful corrections,
or navigation, helping you move anywhere in your code
and open or locate what you need, or even the debug extensions.
Visual Assist is written by C++ developers for C++ developers.
It includes everything you need and nothing you don't.
It has a low UI philosophy.
It won't take over your IDE, but will show up when useful.
It's there to help, not to advertise itself.
Visual Assist is relied on by the developers building software you've used.
Whether that's office suites, operating systems, or games,
software you use was built with Visual Assist.
Get the same tooling for your own development.
Visual Assist supports Unreal Engine 4 and many versions of Visual Studio,
including VS 2019 and Community.
Get it at wholetomato.com.
So I was looking at some of your recent posts
and I saw this one about illegal delegate assignments
and the answer that you kind of posted
to the question in the blog involved coroutines.
And I was wondering how much the Windows code base
is starting to use coroutines.
Yeah, I mean, coroutines are still relatively new to the C++ language.
It was Gor Nishinov, who was the proponent behind it,
and he did it at Microsoft in the Visual Studio compiler.
And so, in a sense, we were sort of in on the ground floor of coroutines.
And, of course, Kenny Kerr with C++ WinRT did a great job of making coroutines easily consumable for most people.
And that library is growing in popularity in Windows.
And so coroutine use is growing.
We're not afraid of modern C++ anymore.
We can use exceptions. We can use st++ anymore. We can use exceptions.
We can use std vector.
We can use coroutines.
It's not like we're going to go in
and rewrite all of our old codes.
Like, you know what?
Let's totally rewrite this thing,
but use coroutines instead.
It's like, no, no, no.
On a project the scale of Windows,
that would be ridiculous.
It would take you longer to do that than just to rewrite the whole thing from scratch.
But at least we're happy to use coroutines in our new code.
And eventually the new code becomes sort of the code that's being actively maintained.
Windows is some ridiculously huge code base, but most of it is not changing.
There's only a small percentage of it that is under active development that's getting features
added, and most of the rest of it is in maintenance. It's just there. It works. There's no reason to
change it. Just let it do its thing. That's an interesting, I feel like, kind of topic here.
If you've got this giant old code base,
it works, you don't want to break anything,
you're leaving it alone,
you're doing new development.
Do you ever have a problem
where the new and the old need to interact
and you're trying to figure out,
okay, well, what's the best way here?
Well, the old code can't take a vector
or doesn't use templates or whatever,
and you have to, I don't know,
marshal between them in some way.
Yeah, we sort of had this problem back as Windows developed.
Windows 1.0 is written in assembly language.
A good chunk of the user interface code is written in C.
And so as Windows evolved, more and more of it got ported over to C until Windows 95,
most of the user mode code was in C.
Most of the kernel code was still written in assembly language.
And so a lot of the user mode code still has a C history.
And so as we adopted C++ over time, because Windows 95 was being written like 1993 timeframe. And that point C++ was still this new cool language
that the hipsters used, but was like,
oh, I don't know about this cool new language.
It could be the next small talk, right?
And so Windows 95 sort of stuck to C just to play it safe.
But then eventually C++ migrated in.
But it meant that you were in this transition phase
where you had a code base that was mostly in C
and you're adding C++ stuff,
which meant that you couldn't really go all in on the C++
because it still had to interop with the C code.
And so as we sort of migrate over to C++,
we sort of treated it more as C with classes
than as a whole new language.
So we didn't use exceptions.
We didn't use RTTI.
But now we're sort of more willing to embrace
the modern C++.
So we're all good.
It's like, yeah, std unordered map.
Great stuff.
Std vector.
We love you.
But it means that you have to be careful whenever
your code crosses
a module boundary because that other module
may not be written in C++.
Or it could be written in C++ but
compiled with a different version of the compiler.
And so you
don't have ABI stability.
Or it might be compiled, you know, because
we have like multiple C runtimes in the system. There's, you know, and or might be compiled, you know, because we have we have like multiple C
runtimes in the system, there's, you know, the UCRT, there's MSV CRT, there's VCRT. So, you know,
there's multiple runtimes, and you and you know, exceptions, and those types of things are not
guaranteed to be portable across runtimes. And so whenever there's a module boundary, you have to
sort of drop to sort of a C style, very plain, simple ABI, but at least whenever there's a module boundary, you have to sort of drop to sort of a
C style, very plain, simple ABI, but at least the code within a module, you know, where we,
we go nuts. Like if you're running a brand new DLL is like, yeah, good job, go crazy.
Just don't throw exceptions out of your module, because you don't you have no idea the color
may may not be written in it, you know, may not be written in C++.
This is really interesting, because we just, well,
between the two of us, we've brought up ABI compatibility with almost every guest that we've had.
And you're talking about needing to maintain ABI compatibility
even within your own project in source code that you own,
because some modules might need to be compiled with a
different compiler or or or using or using different versions of the runtime library okay
so how some some use msvcrt some use ucrt we're trying to get everybody to to move to ucrt but
of course you know this is not like something you can do overnight it's like you know what everybody
we're switching over and then the bugs come in because of some subtle
changes between the two. And what about the compiler? Are you trying to update some of those
older modules to all use the same C or C++ compiler, at least? Yeah, for the most part,
there's a single compiler, a single version of the compiler that is identified as this is the
compiler we use to build Windows.
So everybody's using the same compiler, but they may not be using the compiler with the same flags.
Right.
So like, you know, Z, whether WCAR is a native type or an alias for unsigned short,
you know, whether RTTI is enabled, you know, all these random compiler flags.
Every compiler flag, I'm sure you can find some combination of it somewhere.
And so even though they're all using the same compiler, they're not all using the compiler the same way.
And so we still have to worry about interop issues.
And your role is like debugging, you know, when things go bad with application code. How often do you come across things like this where they are linking
to a different C runtime than they thought they were, or there's an ABI boundary
issue or something like that? Sometimes that'll happen, but that's not usually
the problem. It's because the apps, because it's like when the apps
call into the operating system, we try to identify, you know,
the interfaces into the operating system are all
ABI level. You know, operating system
functions don't throw exceptions.
And so, you know, the question
about, oh, what do we do about exceptions is like, that's
not an issue because we don't throw exceptions. We
return H results. And it's up to you,
the caller, to figure out, well, maybe I want to turn this H
result back into an exception, if that's what you want.
So the problems
there aren't
really apparent at
the operating system level.
Any mismatches don't really
show themselves because
the ABI boundary sort of
erases all of those
issues because you can't pass a std vector
to create window.
There are sometimes problems
where we mess up and
we let an exception escape and and then excitement happens because then people like can then try to
work around it and it's like okay i'll catch the exception but they only catch it using like oh
but then you know but this program used the visual studio 2013 compiler and it catches that
but now in visual studio 2019 we're throwing this exception, and he doesn't know what to do with it.
And you know, so and so things get weird. But but the idea is about like exceptions crossing the
module boundary. That's basically our own fault. Sometimes we have problems the other way where
like we'll call out to the app registers a callback, we'll call it and they will throw an
exception. And then crazy things happen is they might they might like catch it like it might they
call in they call into the operating system the operating system calls back they throw an
exception expecting their outer outer guy to catch it um and it just so happens like no we we changed
our code in the middle so it uses exceptions too so we end up catching it in the middle
and then you know and then and then bad things happen and you know all of these stem from
somebody breaking the rules.
And unfortunately, it's very easy to break the rules because there's usually nobody running around
catching you when you break the rules
until your rule breaking causes a problem.
It's a lot like our legal system, right?
If you break the rules but nobody catches you,
did you really break the rules?
Right, right.
And then finally somebody catches you
and then you're in big trouble. You know whenever i'm using windows api functions directly and i'm dealing with these
h results and i'm like oh i got an error code i have to remember to not ignore this and check
what it means and but you're telling me internally a lot of these libraries might actually be
throwing exceptions and then catching their own exceptions and translating that back to an h
result on the ABI boundary?
Yeah, internally, that's what our modern,
like I said, we're sort of adopting modern C++ now.
And so a lot of our functions at the entry point,
like APIX is like, okay, the first thing it does
is set up a giant try-catch block.
And it does a catch, it does a big catch at the end
and converts the exception
to an h result and returns it wow can i call this the c++ version that doesn't do that
well but you'd have to be using exactly the same compiler that we are with exactly the same
switches that's a good point yeah and you know and that means every time we upgrade the compiler
you're gonna have to upgrade your app and then you have to say your app is like, oh, hang on, what build am I running on?
Oh, yeah, that version of Windows use the Visual Studio 2017 compiler with these switches.
I better use the version that's built.
Yeah, so I don't think that's a good idea.
It just reminds me of how Windows really is really, really good about being able to run
surprisingly old programs today on a modern Windows 10 or whatever.
And I guess, yeah, that contributes to that.
Yeah, trying to be very, very tight with what the contract is.
And the fact that, yes, it is annoying that the only error communication between two modules
is an H result.
But that also means that you can you can rev the two sides
independently because the interface between them doesn't involve anything that's compiler dependent
right it also means that for example if you're writing c sharp code or visual basic or javascript
you can still call them because you don't have to worry about like oh this if it's like oh yeah
here comes an exception is a c++ exception Too bad my program is written in C sharp.
Right.
It's like, I'm not going to be able to catch this.
What am I going to do?
What is, you know, what is what is std bad alec is like, I have to remember to convert
std bad alec into out of memory exception and std out of range and out of range exception.
Oh, great.
Here's std system error.
I have no idea to do with this one.
We didn't have this on our show notes.
But since we're talking about the Win32
API, I think we mentioned
a news article a couple
weeks back about how
there was work being done to expose
the Win32 API to
C++ and then possibly other languages.
Do you know much about that?
Is that something you're actively working on?
I'm not actively working
on it, but I know the people who are. And the idea here is that the API itself is going to be described, as right now,
the only way you can call the API is to use the header file, right? The way the API is described
is described in this really low-level language called the C compiler.
And so you have to understand C macros and all the other wacky stuff that the C language does to you and forces you to understand.
And the idea is that instead of expressing the APIs using header files,
we express them using a higher level description,
which is machine readable,
in like, where you don't have to write a C compiler to be the machine. And so you can like
find it's like, it's going to tell you it's like, Oh, yeah, I have a function called create process,
it returns a bool, it takes eight parameters, the first parameters, you know, and so on.
And you can you can figure this out without having to write a C parser. Instead, you just,
you know, you write this other parser.
I forget what format they use.
I don't know if they're using ECMA or something.
And the idea is that you can write a tool
to parse this more abstract representation
and then use that to turn around
to generate bindings for your language of choice.
It's very similar to what C++ WinRT does.
It takes the WinMD files that comes out,
parses them, and then spits out a bunch of header files
that let you call them in the appropriate way.
And C Sharp does the same thing.
C Sharp reads the WinMD files, and it's like,
oh, okay, I know how to call all of these functions now.
And you can call them from your C Sharp program,
and the C Sharp compiler does the work of,
you know,
turning it into an appropriate language call and the JavaScript compiler,
same thing,
or the,
the JavaScript interpreter slash compiler.
Who is JavaScript and interpreter or compiler nowadays?
It's both.
It's like a floor wax.
It's a dessert topping.
It's a Christmas card.
JavaScript is like,
it's this thing,
man.
But yeah,
so,
you know, JavaScript can parse the WinMD and then expose all of these APIs directly into JavaScript. So the idea is to bring that sort
of level of expressiveness to all of Win32. So you can pass this type of metadata stuff into
some sort of processing engine and for example automatically
generate p invokes for c sharp for you that's the theory as i understand it i could be completely
wrong so it's still still in development and quite a ways away from uh getting into the hands of c
plus developers yeah i'm not sure what the what the level of progress is but if if you want to
take a peek at what it what it led to like the existing documentation on docs.microsoft.com
is driven by sort of early explorations in this type of thing.
So all of the API-level documentation is driven by,
like it used to be driven by running the C compiler
and then extracting header declarations
and function declarations out of the, out of the
asking the compiler, it's like, Hey, instead of generating code, could you just tell me all the
functions you found and then using that to, to generate the output. And so that, that was what
generated the, the, uh, the documentation on docs.microsoft.com for all of the Win32 stuff.
And, uh, and I think that is sort of the, the project that led to the Win32 stuff. And I think that is sort of the project
that led to the Win32 metadata project.
And, you know, it's like, okay, you know what?
Instead of being this top secret thing
that only the docs team gets to use,
we'll try to make it available to everyone.
Sounds cool.
And so it would let you do cool things like queries,
like, hey, I have, you know, I have an H font, show me all the functions
that take an H font, show me all the functions that return an H font, right? And you can you can
do these sort of higher level metadata queries against against the database, instead of having
to do grep, and then say, No, no, that's not the age. That's just that that's a structure called
H font. I don't care about that one, you want to find all functions that take more than five parameters,
because those are stupid functions.
Because they're bad.
All functions that have output pointers that are com pointers,
but don't have an RFI ID.
I don't know if you're the sort of person who just likes just like find they're like find me the enum with find find me an enum
with the most number of members right this type these type of metadata i like to make these sort
of weird queries or find me the enum with the longest name right this is like a query you can
make now against this metadata that's like 10 more blog posts right there yeah for you i'm i i've
never i've not even seen this metadata
So I'm just talking off the top of my head
But we do have tools that do the same thing
With the Windows runtime metadata
And those are types of queries that I like to make
Like what's the enum with the highest number?
It's like, oh, yes, this enum has a value of like 17 billion
That's nice
Okay, maybe not 17 billion
1 billion
It's possible an enum can have an underlying type of a 64 Of a UN64? That's nice. Okay, maybe not $17 billion. $1 billion.
It's possible.
An enum can have an underlying type of a 64.
Oh, a U and 64?
Yeah.
That's one crazy enum.
So another thing I wanted to ask about,
we recently had another guest on who talked about C++ and COM
and how it's become easier in recent years.
And I was wondering if this is something
you're familiar with,
if com has become easier to program with more recently.
It's not something that I've really noticed.
I mean, I grew up with com.
So to me, com is like, yeah,
com is how you communicate between two components
that know nothing about each other,
you know, language independent, all that stuff.
And so, yeah, there are COM wrappers,
like C++ WinRT has some COM helpers.
There's the Windows Implementation Library,
which we recently open sourced,
that also has a bunch of helper functions
for managing COM.
So I couldn't find which library
your guest was talking about.
I couldn't figure out which library it was.
So I'm happy that there's something that got better,
but I don't know specifically what it was they were referring to.
But yeah, I'll take credit for it.
I'll take credit for that thing.
That sounds great.
You've mentioned Assembly C and C++ being in Windows,
and then with the discussion of COM
and this question of interoperability with C Sharp and VB
and those things, I'm just curious,
have you seen other languages also come into the Windows core?
C Sharp, Visual Basic, Pascal, in the future, Rust?
Do these things come and go?
Have they ever come briefly?
Are there parts of windows written
in visual basic today or something like that yeah the the problem is that once is like yes we could
write this cool new thing in c-sharp but there are people like games who like they're like keep
that stuff away from me i'm not calling any ap API that involves a garbage collector. Okay. Right. And so
platform level stuff
we tend to keep pretty
low level. Like, you know, there's
no GC, there's no...
It's pretty much C and C++ for stuff
for low level platform stuff
because other apps are
going to be upset. Like some categories
of apps are going to be upset. It's like, yeah,
I open a file open dialog and then this you know a javascript interpreter got injected
into my process and they're going to be like uh get that thing out of here uh especially like
with c-sharp and and it's like oh yeah congratulations we loaded c-sharp into your
process but it's not a version of C Sharp that your process is compatible with.
And so that's going to be a problem too.
So we try to minimize the dependencies
of operating system level services,
things that are going to be used by third-party programs
because they tend to get kind of concerned
when it's like, yeah, I call this new function
in order to display a
toast message, and somehow you loaded both JavaScript and C Sharp into my process. However,
you know, we do have things that, you know, are built on top of the core operating system, you
know, a lot of our apps. And those are certainly happy to use C Sharp, because it's not like,
you know, them switching to C Sharp is going to affect anybody else, because they're at the top of the food chain, to affect anybody else because they're at the top of the food chain.
It's when you're at the bottom of the food chain,
you have to be more careful.
You don't want to give everybody mercury poisoning.
So do you see a future where C++ could theoretically,
at least partially, be replaced by Rust if someone wanted to
because you could compile the DLL in Rust and still provide
that hresult ABI that we were talking about earlier. Yeah, I mean, I'm not too familiar
with what runtime support Rust requires. Right. So I hope I'm not going to see a Slashdark article
saying, you know, Microsoft engineer says Rust is coming to the Windows core.
That's a good point.
That happens.
Yeah, I don't say anything like that.
Yeah, but I think, but isn't Kenny working on like Rust WinRT?
Like he's bringing.
I don't know.
He's bringing, there's, yeah, I think, yeah, there's also an effort to bring the Windows runtime to Python.
I'm not sure how far that went.
And so there's certainly the ability to consume Windows APIs from Rust.
Whether the APIs themselves will be implemented in Rust, I don't know if we're ready for that yet.
Okay.
And certainly, we would have to get the runtime dependencies down before a lot of our customers would be willing to call something
that uses it. I think Rust statically links in its
runtime, which is why their binaries can be gigantic, but
I could be wrong on that. Irrelevant. Just curious.
I myself have never worked with Rust.
I remember a friend of mine, back in the early days of the internet,
he registered Rust.com.
This was before the Rust programming language.
It was just a webpage where he talked about the wonderful properties of iron oxide.
He put some ads on it and made a little change, paid for the domain hosting.
Ah, the early days of the internet.
Ah, the early days of the internet.
You can create a domain called My Record Collection.
And it would just be your record collection.
And anybody who wanted to go in and browse your record collection.
It's like, oh, wow, he has that album too.
That's great.
Back in the days, we have a website called what i ate
for breakfast today.com and it would it would just like oh i had eggs today and people and people
would come visit it's like oh i wonder what fred had for breakfast today oh my goodness now nowadays
nowadays it would be called like breakfaster yeah i the first probably the first five domains that
i registered i'm like oh that sounds like a good name
and I just went and registered
and now the last five that I've registered
I spend like a week trying to come up with something
that isn't taken
that's not already taken
it's like I think like every word in the dictionary
has been taken now you have to try to find
two word combinations that haven't been taken
we've talked to several
other guests before who work on like really large code bases like Google.
And I'm sure the Microsoft Windows code base is similarly hugely large.
And, you know, you've talked about all this old C code, maybe even old assembly code.
And I'm wondering, do you ever have any tooling to like go through and update that code in any way?
Because I think that's something that the Google team has talked a lot about.
Right, Jason? Yeah, the Google team's all
constantly automatically updating all
the things. Is Windows doing anything similar
like that? I'm not aware of anything
that's going to go in and try to...
At least now that we're
all on Windows NT and the Windows 95 code
base is gone, there's
vanishingly little assembly language in
Windows NT, and so at least the assembly language stuff is mostly gone. There's vanishingly little assembly language in Windows NT.
And so at least the assembly language stuff is mostly gone. But in terms of like, you know, C, a lot of the stuff has to stay C because it runs in kernel mode. Kernel mode is very concerned
about like, because like C++ doesn't let you control which, like where's the V table going
to be stored? Is it going to be stored in pageable memory or non-pageable memory?
So it makes it very hard to use C++ in kernel mode, where this type of stuff is much more concerning,
where you have to have much more careful control
over where the code gen is happening.
And so, at least in kernel mode, it's still pretty much mostly C,
because C lets you control that sort of thing. Up in user mode, it's still pretty much mostly C because C lets you control that sort of thing.
Up in user mode, it's like, hey, go crazy, people.
I think you were discussing how Windows maintains ABI compatibility
between all the modules on top of, obviously, API compatibility.
If the ABI is stable, the API must be.
And Google's code base doesn't really care about those things,
which is one reason why they can easily update their API whenever they want to.
Just as an aside.
Yeah, maintaining stability between modules is important
when the modules are managed by different teams.
It's like, oh, here's the FRED team.
It's like, oh, the Shell team, we need a function from the networking team
in order to display your Wi-Fi strength.
And if you go around changing too much,
somebody's going to get mad.
Something's going to break.
A test is going to break.
The community, you miss a spot.
It often gets quite complicated.
So we try to maintain tight contracts,
even for internal components, to minimize these
types of, you know, this risk of change. It's sad, you know, when your code base is 3.5 million
files, you got to be careful. 3.5 million files?
Yeah, I think when the virtual file system for Git was announced,
I think I'm trying to remember, I think Brian Harry,
they said that Windows is the largest known Git repo.
And he said that, yeah, it's 3.5 million files in one monorepo.
And that's just Windows.
And that's just core Windows.
That's not counting the weather app, the apps that ship on top of Windows.
Core Windows, most of the stuff that just gets laid out on the machine as part of install.
That's 3.5 million files goes into every build.
So how well do you personally, if you're like, oh, well, I need to find this bug.
I know it's going to be in this subdirectory
until you get down to this file.
Like, do you keep a mental map at all of 3.5 million files
as you're working on with Windows?
I mean, no, of course not.
You can't keep a mental map of 3.5 million files.
If it's organized in a nice hierarchical way,
you might be able to.
I don't know.
No, well, the thing is, you know,
you know the structure of the thing is you know you you know
the structure of the code that you work with you know the structure of the code that you interact
with like for example you know like the the the taskbar wants to know the network signal strength
so it can display the you know number of bars on the thing so it's like well they they probably
you know deal with those people a lot they know it's like, well, they probably deal with those people a lot. They know it's like,
oh, yeah, their code's right here. Because every so often when I have a problem, I have to go look
at their code. And so I have it bookmarked. It's right here. But of course, if it's like, oh,
it's crashing in some component I've never heard of, how am I going to find it? And the answer is, well, fortunately, you know, the Azure DevOps, we enable search indexing on the repo.
So you can just type in something.
It'll hunt for it across 3.5 million files.
Nice.
Yeah.
When you think about it, it's kind of surprising.
It's like, wait, I can type something.
And within a couple seconds, it just searched 3.5 million files for it.
And then you get mad because it couldn't find it.
And it's like, no, no, no, it was in there. It was searched 3.5 million files for it. And then you get mad because it couldn't find it. And it's like, no, no, no, it was in there.
It was in there.
You just missed it because there are too many hits or something.
I mean, it's just impressive that you can search a 3.5 million file code base in a few seconds.
Yeah.
Does IntelliSense work with Windows?
Do you use Visual Studio?
We have Visual Studio.
There are many of our projects that are built in the form of
Visual Studio projects. So we use MSBuild to build them. So yeah, you can just load them up in the
Visual Studio. And even for projects that aren't, you can still do the open, you can open a directory.
Open folder. Yeah, open folder. And we have some private extensions that sort of integrate that
with our internal, our non-MSBuild build system.
So you can actually kick off builds from inside Visual Studio and the IntelliSense all works.
It's pretty cool.
Awesome.
So we already mentioned how you sometimes get July 4th emails from Herb Sutter.
That happened that one time.
Yeah.
How closely do you work with the Visual C++ team? Like, does the Windows team give them,
hey, like, we would really like to see this add to the C++ language?
Does that communication happen a lot?
That, actually, I don't know.
Like, there's a group of people
who's in charge of interfacing with the languages team.
I'm not part of that group.
And so the only time I learn about them
is when they send out an announcement to everybody
saying, hey, we're upgrading the entire
Windows project to the latest version
of the, to this version of the Windows
of the Visual Studio compiler.
You know, they have
a separate branch where
it's like, hey, we have an idea. We're going to pick up a new
version of the compiler. And they throw it in
and spin a build and see what
blows up. And then after they fix all
the problems, because oftentimes the changes
are things like, oh, we improved conformance.
And it's like, oh, we found 50
people whose
code was technically wrong, but they got
away with it, and now they don't get away with it.
This poor team goes
in, and they basically have to run around all
3.5 million files fixing build breaks
from things they've never seen before. Yeah, it's a lot of fun and then yeah and then like okay great and then they send
out mail saying okay we're pulling in a new version of the compiler as well as like 350
bug fixes that had to go in because there were bugs that the compiler found i love that so even
the yeah the old code that's in maintenance is getting bugs just
naturally fixed as the compiler gets better, it sounds like. Well, it's not so much that the code
is getting fixed. It's just, it's that like, you know, the code was doing something wrong,
but the compiler never noticed. And, but, you know, and it's like, well, it was doing something
wrong in the sense of what you were doing was technically not legal, but it worked anyway.
And now it was technically not legal, but it worked anyway, and the compiler never noticed.
And now it switched to technically not legal, worked anyway, but the compiler yelled at you.
And so they had to go in, and for every compiler error, they had to say, okay, is this a real bug?
Or is this just, oh, they cast, they, you know, they used the, you know,
they cast something away the wrong way or something like that.
Because, you know, it's not like these guys are going to go in
and like fix real bugs.
It's like, yeah, yeah, we're responsible for 3.5 million files.
We just fix bugs everywhere.
It's like, no, no, our goal is to make sure that ingesting
a new compiler doesn't break anything.
Right.
So make sure that when the new compiler comes in, everything still builds.
It's like, oh, yeah, the new compiler now detects some use-after-free problems,
so we'll go in and fix those.
Or the language rules change, and the scope of a variable is now tighter,
so we had to move the declaration outside the for loop or something like that.
Or it could be, for example, with the coroutines, since Visual Studio was one of the
first compilers to incorporate coroutines as part of the exploration. And so it supports a lot of
legacy syntax from stuff that eventually did not get approved and they're gradually removing it.
And so that's going to break code that was accidentally relying on the old syntax.
Interesting.
Right?
Like a wait without the co-wait.
Yeah.
Like it used to be that before the co-return keyword, it was just return.
The single return keyword served double duty.
But then that didn't make it into the final version of coroutines. But the Visual Studio
compiler still lets you get away with saying return instead of coreturn in order to accommodate
old code that was written to earlier versions of the coroutine proposal. And as the Visual Studio
team works on improving their conformance, then all that old code starts kicking up compiler errors,
saying, oh, I'm sorry, you used return.
You should be using co-return.
And so that team of people goes in and patches them all up.
Is there anything else you want to ask?
Yeah, I'm curious if there's an exhaustive, I'm sure there is,
but a test suite for Windows when something like,
when they go and change the compiler and then change this code,
is there some giant test suite that runs to say yeah okay we you didn't break windows it's it's kind
it's kind of hard to like decide to test all of windows like we do have tests they run um you know
they're unit tests and functional tests but it's it's not like you're going to be able to write
tests to cover 3.5 million lines of code most most of which were, you know, like tons of which were written before sort of modern testing
philosophy.
Right.
And so a lot of that stuff is just like, if it if it boots, then great job.
You know, boot it, run it, run it through our app compat tests, run it, run it through
all the unit tests, run it through our functional tests.
Hope that if there's a problem, one of those things will catch it.
But it's not like every single line of code, there's a test for it.
Oh, yeah.
Wow, that'd be impressive.
You'd end up with a test suite as big as the code base.
Yeah, the test suite would be bigger than the code base
because the test suite would have to exercise each line of code
in all the possible ways.
Right.
And it would also take weeks to run.
Yeah.
Do you have any idea how many lines of code it is
besides 3.5 million files?
I have not done a word count,
so I don't know, but it's a lot.
Yeah, it would have to be a lot.
Yeah, it's a lot of files. I don't know exactly but it's a lot. Yeah, it would have to be a lot. Yeah, it's a lot of files.
I don't know exactly how many.
Awesome.
Some numbers are just so big you just don't want to think about them.
Right, yeah, probably.
Okay, well, Raymond, it was great having you on the show today.
Thanks so much for coming.
Oh, thanks for having me, guys.
Obviously, people can find you on the Old New Thing blog.
Anything else you want to plug?
There's the Old New Thing blog.
My GitHub ID is Old New Thing blog. Anything else you want to plug? There's the Old New Thing blog. My GitHub ID is Old New Thing.
My Twitter,
which is called Chen Cravit,
it is actually
set up by Laura Butler, who used
it to parody me, and then
she decided to let me have it.
And
there are a few
repos on GitHub that I manage.
The UWP samples repo and the Win32 classic samples repo.
I'm sort of the managing editor of those guys too.
So yeah, I'm sort of all over the place.
All over the place in Windows land at least.
You're not going to find me over in Rust land.
Not yet at least.
Give it time.
Okay. Thanks, Raymond.
Thank you. See you guys.
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.
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.