CppCast - VS2015 and the Universal CRT
Episode Date: August 3, 2015Rob and Jason are joined by James McNellis to discuss new features for C++ developers in Visual Studio 2015 and changes made to the C runtime. James McNellis is a senior engineer on the Visual... C++ team at Microsoft, where he works on C++ libraries. He’s spent the past three years working on a major redesign and refactoring of the Visual C++ C Runtime, which culminated in the release of the Universal CRT with Windows 10 and Visual Studio 2015. He occasionally speaks at C++ conferences and was at one time a prolific C++ contributor on Stack Overflow. News C++'s Rule of Zero CppCon 2015 Program Setup Changes in Visual Studio 2015 Affecting C++ Developers James McNellis @JamesMcNellis James McNellis's Home Page James McNellis on StackOverflow Links Visual Studio 2015 RTM is now available Introducing the Universal CRT CppCon 2014: Stefanus DuToit "Hourglass Interfaces for C++ APIs" MVA Course: C++ A General Purpose Language and Library Jump Start The Visual C++ Team is hiring!
Transcript
Discussion (0)
This episode of CppCast is sponsored by JetBrains, maker of excellent C++ developer tools including
CLion, ReSharper for C++, and AppCode. Start your free evaluation today at jetbrains.com
slash cppcast dash cpp. And by CppCon, the annual week-long face-to-face gathering for
the entire C++ community. The 2015 program is now online. Get your tickets today.
Episode 21 of CppCast with guest James and look at the CppCon 2015 schedule.
Then we'll interview James McNellis
from the Microsoft Visual C++ Libraries team.
James will talk to us about some of the new features
for C++ developers in VS 2015
and educate us on the changes his team made to the C runtime. Welcome to episode 21 of CppCast, the only podcast for C++ developers by C++ developers.
I'm your host, Rob Irving, joined by my co-host, Jason Turner.
Jason, how are you doing today?
I'm doing all right, Rob. How are you doing?
Doing good. I am finally settled in the new house.
My wife and I have been working like insane people over the past few days, getting unpacked.
And our kids are getting here tomorrow.
My parents are bringing them down.
So things should start getting back to normal.
I'll apologize again for missing another week of the show.
But things were just a little bit too hectic earlier this week.
It has been a little erratic lately.
Hopefully we can get to a more regular schedule again soon.
Yeah, hopefully.
My one concern is the new place where I put my desk is doubling as a guest room.
So anytime my parents or my in-laws come to visit, I might need to work around that.
So we'll work with that as it comes, though.
I'm sure it won't be too bad.
All right.
Okay, so at the top of every episode, I like to read a piece of feedback.
A couple, this may have been a week or two ago,
I got a tweet from Twitter user DatGamer, though,
and he actually says, can you do a show about pointers?
I know the basics but still struggle
how they're implemented in real life
code. So I thought this was interesting
because I kind of assumed that the majority
of listeners to CppCast
were more intermediate
to advanced C++ programmers
but I think it's pretty cool that we might have more
beginner level
listeners out there.
But at the same time I don't really think we're going to be doing episodes and kind of
more basic concepts like pointers.
Do you have any thoughts about this one, Jason?
I know it would be interesting, but I just feel like in general, something like that
would be difficult to talk about without being able to give any
illustrations or have a
whiteboard or something else available the one thing i will say to this listener is i know there
are a ton of great resources for getting started with c++ and other programming languages online
we're going to introduce our guest james in a moment and I think he actually worked on a free online video course that does an introduction to C++.
So resources like that are probably better to look at than something
like this podcast. I'm definitely glad you're listening,
but we focus more on new libraries
and new features and IDEs and things like that.
Maybe it's some more advanced concepts than raw pointers.
But we'd love to hear your thoughts about the show.
You can always email us at feedback at cppcast.com.
Follow us on Twitter at twitter.com slash cppcast.
And like us on Facebook at facebook.com slash cppcast.
And you can always review us on iTunes as well.
Really appreciate the iTunes reviews as they help us get more listeners.
So joining us today is James McNellis,
who I already mentioned.
James is a senior engineer
in the Visual C++ team at Microsoft,
where he works on C++ libraries.
He spent the past three years
working on a major redesign and refactoring
of the Visual C++ C runtime,
which culminated in the release of the Universal CRT
with Windows 10 and Visual Studio 2015. He occasionally speaks at C++ C runtime, which culminated in the release of the Universal CRT with Windows 10 and Visual
Studio 2015. He occasionally speaks at C++ conferences and was at one time a prolific
C++ contributor on Stack Overflow. James, welcome to the show.
Thank you very much. It's good to be here with you today, finally.
Yeah, it's great to finally have you on. Sorry for all the scheduling nightmares between the two of us.
Man, I got to say, trying to be a prolific contributor on Stack Overflow, that's like a job to itself.
Yes, it was.
Though it was a bit easier five years ago when I started because there were a lot fewer people
and all of the easy questions, if you will,
hadn't yet been answered.
And so nowadays, someone asks an easy question
and it immediately gets closed as a duplicate of something else.
But back then, there was nothing to resolve them
as duplicates of things.
So there was some benefit there.
Yeah, that's probably how I got some of my early points
on Stack Overflow also.
Yeah, but I don't have nearly as much time as I used to.
So I usually, mostly now I just answer details
about Visual C++ or issues that people run into
with the software that we build.
Well, it sounds like you're the man
to answer some of those questions.
Yeah, I know I've gotten a fair number
of Stack Overflow points by answering questions about C++ CX
and Windows apps with C++
there doesn't seem to be a lot of action going on there
the obscure thing that you are an expert in
whatever that happens to be
we wanted to go over a couple news articles
before we start talking to James
but James, feel free to jump in with any of your comments.
The first article is C++'s Rule of Zero.
Jason, did you want to do an intro for this one?
Sure.
This article just struck me as interesting.
I had heard some mention of the Rule of Zero before before but this article is interesting to me because it just outlines the idea that if your class does not do any resource management then it should not define
any of the special functions that the compiler will define for you such as the copy move
constructors assignment move assignment and destructors and it can really simplify and clean up code if you are careful with it.
Yeah, it definitely seems like good advice to follow.
Yeah, I think definitely it's a good read for anyone
and it's good tactics to follow when writing new classes.
If you don't need to deal with any of these,
if you're not working on resource management,
then you shouldn't be writing them.
Or even try to make a point of not writing any of them.
Yeah.
I actually found myself thinking about this exact article
with some code I was working on earlier this week,
and I don't know if it actually changed the way
that I implemented the class that I was working on,
but it certainly just made me think while I was working on it anyhow.
James, do you have a chance to read this one?
I had not yet had a chance to read it.
But in general, I absolutely agree with the advice based on what you guys have been saying just now.
Okay.
The next article I wanted to mention was that the CppCon 2015 schedule is now out.
So CppCon is coming up quickly at the end of September. It looks like it starts September 21st.
And all the speakers and sessions are now posted.
So you can take a look at what's going to be going on there.
It looks like they're going to have Jarn Strusup for the keynote,
which should be really cool.
James, I saw you were not listed here,
but a couple of your colleagues on the Microsoft Visual C++ team are.
Yeah, we're going to have a lot of Visual C++ content there.
I know that Steve and Ayman, who are two of our group managers,
will be giving a talk on what's new in Visual C++ 2015.
I think Goran Nishinov, one of my colleagues on the libraries team,
who's been responsible for a lot of the Resumable Functions work,
the Await work, will be giving a talk.
My former manager, Archer Loxberg,
who is the editor of the ISO C++ concurrency technical specification, I think is giving an editor's report.
Stefan, I know, is giving a talk on something, though I don't actually know what yet.
I am not giving any talks, and I'm actually very glad not to be giving any talks. It's been quite a while since I've been to a conference and actually been able to just enjoy myself
and not spend the first half of the conference editing slides
and worrying about, oh my gosh, is everything correct?
So yeah, I'll be there mostly just to socialize with people.
So will both of you be there?
I'm not sure if I will be. I know Jason will be.
I will definitely be.
And I think actually the talk I'm giving is up against Gore's.
So I don't know if a lot of people will be attending mine or not.
Well, good thing they're all recorded.
Right.
Yeah, that happened to me at CppCon last year.
My third talk was a representation of the Unicode and C++ talk that I gave at C++
Now, and I was opposite
Andre Alexandrescu, and
I think I had maybe 10 people in the room,
which was a bit disappointing, but I was glad that
everyone else got to go see Andre's talk, because I would have
actually much rather been there.
I see
your colleague James Radigan is also on this
list doing a talk on Clang
being used in Visual Studio.
Is that right?
Yep.
So he leads our backend team, the optimizer and code generation team.
So that's what we call C2.
So C1 and C1xx are our compiler frontends, and then C2 is the compiler backend.
So, yeah, he'll be talking about a lot of our efforts to try and get basically the Clang compiler front end bound to the Visual C++ compiler back end.
And to get, you know, to make it, I guess, a better experience to build C++ software using Clang on Windows.
Very cool.
I also saw Kate Gregory, who I think you did a talk with last year at CppCon, is doing something on Stop Teaching C,
which is an interesting name for a talk.
I guess she's pushing for just teaching C++ instead of teaching C first.
Yeah, I guess avoiding the teaching the C-isms first.
So I know that a lot of times people learn the bare-pointer arithmetic
and things like that first
before they learn all of the C++ things that build on top of it.
And so I expect she'll be talking about, no, let's stop doing that
and try and teach the higher-level concepts before diving into the lower-level concepts.
Right. Makes sense to me.
Okay, and the next article, very relevant to you, James.
Setup changes in Visual Studio 2015 affecting C++ developers. So this article is basically saying how in Visual Studio 2015, C++ is no longer in the default install. It's now an optional checkbox for you to tick off. And I saw that, you know, a lot of C++ developers might think that it's becoming like a second class language for Microsoft and Visual Studio, but that's definitely not the case,
right? That is definitely not the case. Yeah, I know. I don't know, some of us sort of expected
that that would be, you know, some of the reaction that we would get. So if you remember back, if you used Visual C++ back in the,
basically as recently as Visual Studio 2008,
you'd install Visual Studio and you'd have a ton of checkboxes
and people said, oh my gosh, our customer said this is so confusing
and so we want fewer checkboxes.
And so gradually we ended up to the point where I think it was in 2010 or 2012 where most of the checkboxes were gone and you basically had to install everything altogether.
And it turns out that, you know, we install a lot of things that many developers don't use, right?
If you're building ASP.NET web applications, you may not need any of the C++ tooling or you may not need the Windows phone development tools,
which are quite large because of the emulators and things. So yeah, we're trying to remodularize things so that you can actually pick and choose what you want. Visual C++ was one of the first
things that we ended up pulling out, I guess one of the first big things. And the reason for that
was largely organizational. We're a bit more separated from the rest of the first big things. And the reason for that was largely organizational.
You know, we're a bit more separated from the rest of the Visual Studio group than other parts.
And so, like, we actually have our own branches in which we build stuff to deliver into the main part of Visual Studio.
And so making ourselves an optional component was, I guess, a little easier than, you know, for example, making C Sharp or Visual Basic an
optional component. So I think the important thing is, like, we're not stopping here. It's not just,
okay, now C++ is optional and everything else will always be in the box. You know, the goal is that
gradually, you know, we'll continue moving additional things to be optional. Because
ideally, like, you know, if you're only doing C++, ideally, you'd like to be able to install,
you know, the Visual Studio IDE and the debugger and all the things that you use with C++.
But maybe you don't care about the managed languages or JavaScript development or things like that.
So eventually, if we can get a lot more things to be optional, if you will, that should become better for everybody.
Very cool. And in the blog post I saw, I think Steve Caroll was saying that they're actually seeing more C++ usage, not less.
So it's definitely not the case of C++ was easier to knock off or something like that.
Yep.
Yeah, it has nothing to do with second-classing the language or anything like that.
It's just that, A, it was easier for us to make the Visual C++ stuff an optional component,
and B, the Visual C++ stuff is really big.
We have, I don't know, well over a gigabyte once you include all of the libraries that we ship.
We ship a lot of static libraries, which tend to be very large.
So just because of the size, there was a substantial benefit of moving
ourselves to be optional for all the people who don't do C++ development. I'm curious if you have
the metrics to know what percentage of users do choose to install the Visual C++ tools.
I am sure that we have some metrics on that. I don't personally know what the numbers would look like.
And it's still actually pretty soon to be able to get an accurate picture,
especially since large enterprises aren't going to start rolling out Visual Studio for some time probably.
Right.
And one other thing I think this article mentions is
if you kind of just hit
next next next and don't install c++ it makes it really easy to get it like if you go to open up a
c++ project it'll prompt you to you know do the rest of the install is that right yep um basically
if you go and you know for example try to create a new c++ console project or you know when you get
to the c++ page, it'll say,
hey, you haven't installed this.
Click here to resume setup, and it'll go and start setup again.
I think it has all the boxes checked right.
Okay. That's neat.
Very cool.
And I look forward to more stuff becoming optional
because I never touch any of the ASP.NET stuff,
so I definitely don't need that.
I don't need VB installed personally.
Not anymore.
It's been a while
yeah okay so let's talk some more about visual studio 2015 because that was just released and
there's actually a lot of new features and improvements for c++ developers not just this
whole becoming optional thing that was changed so what do you think some of the biggest changes are that listeners should be aware of? Yeah, so with the compiler front-end side of things, so all the language conformance
stuff, we've made a bunch of, basically a huge amount of effort has gone into improving C++11
language conformance and implementing some C++14 features. And so the net result is that I believe we've implemented
almost everything from C++11 with the exception of expressions FINE.
So this includes everything from compiler-generated move operations,
ref qualifiers for member functions, defaulted and deleted functions,
non-static data member initializers, and there's a whole list of things.
We actually published an article on the Visual C++ team blog,
and we can include a link with the show notes, I hope,
that links to all the blog articles that we wrote up detailing all the new features.
But, yeah, in addition to all the conformance features,
I think we fixed at least 1,000 compiler bugs.
I don't have the numbers,
but the manager
on the compiler team,
Ulzi, wrote a blog article
in which he just listed
all of the customer reported bugs,
so not including
all the internal bugs
that we fixed.
And it just went on
for pages and pages and pages.
And so, you know,
hopefully, you know,
we've got a lot
of quality improvements
over the Visual C++ 2013 release.
From the library standpoint, the biggest feature is we've made a lot of STL conformance improvements.
Stefan has made a lot of bug fixes.
He rewrote, for example, the functional header to fix a whole bunch of bugs with forwarding things.
So that is all quite useful.
As you mentioned previously in my introduction, we did a major refactoring of the C runtime.
I guess we'll probably talk about that in a little bit.
We introduced a few new features to MFC.
I don't actually know what those were,
but I know that there were some MS,
well, there's many MFC developers out there,
but there were a few MFC feature requests that were very highly voted
on the Visual Studio user voice site.
And so we looked at them and found,
well, it would actually be pretty easy to implement those.
And so we went ahead and implemented them.
So, you know, we do actually implement things when people request them,
or we try to.
Does MFC still get a lot of usage?
It's not something I've worked a whole lot with.
It gets...
I hope that there's not a lot of people
building brand-new applications with it,
like starting off saying,
oh, I'm going to build this new Windows application
and I'm going to use MFC for it. But there is an enormous amount of legacy software out there,
and almost all enterprise groups that we talked to, a lot of, you know, people who build industrial
software, or basically anyone who's got software that's more than, you know, maybe 15 years old, has a sizable MFC code base.
So maintaining MFC support for them is obviously very important for us.
Right.
It may seem minor, but the feature I'm most excited about
is the compiler-generated move operations.
Because in my library, I've got like pound if def.
If Visual Studio, then don't do move constructor equals default.
Yeah, I'm also very excited about that feature.
I know I was working on some libraries back in the 2010 era.
And I remember trying to compose move only types and having to write your own move constructor
and move assignment operator.
And it's all boilerplate. You know exactly
what you want the compiler to generate, and the compiler probably knows exactly what you want it to
generate, and it just wouldn't do it. So yes, I'm very glad to see that
we've implemented that in this release. And so easy to get wrong when you're
doing it yourself, even though it's also trivial boilerplate to miss
something. I don't know. I find that's often the case with yourself, even though it's also trivial boilerplate to miss something.
I don't know. I find that's often the case with boilerplate,
that it's so easy to get, when you're typing it out, to get it wrong because in code review, your eyes are just going to glaze over and you're like,
okay, yeah, this is all boilerplate. It must all be correct.
Oftentimes you screw up. Or I do. I don't know about you.
I guess that's the entire point of that rule of zero, so that if you
add a member variable, you don't forget it, basically.
Yep.
So other new VS 2015 features, there are also a number of refactoring improvements for C++.
Is that right?
Excuse me.
Sure.
Okay.
I actually don't know about IDE improvements.
I'm not entirely sure what improvements we've added to the IDE in this release for C++.
I know that we've implemented a few, but I'd have to go and look.
Okay. Okay.
Yeah.
I know, so, you know, one of the other major areas that we've been working on is our support for cross-platform development.
So in the past, in Visual Studio 2013, we basically only supported development for Windows platforms.
So, you know, Windows, Windows Store apps, Windows Phone apps, things like that.
And so in Visual Studio 2015, we've gone and added a ton of support
for building Android apps.
You can actually now build Android apps using C++,
using the Android NDK in Visual Studio.
You can debug them from Visual Studio.
We have an Android emulator.
We also now support debugging processes that are running on
Linux systems. We actually built a debugger engine that binds the Visual Studio debugger,
I guess the front-facing pieces of the debugger that you see to GDB or LLDB on the back end.
And then starting with, I believe, with Visual Studio 2015 RTM, we started introducing support for building iOS applications, including debugging.
I know that for iOS applications, you still actually have to have a Mac, so you can't just build apps using a non-Mac PC. you actually can do some development from Visual Studio, which may be useful for people who are building actual apps
that need to run all these different platforms.
Yeah.
Actually, we talked to Ankit Asthana way back in Episode 3
about some of these cross-platform development,
but I think that was still maybe before release candidates,
and I think at that time it was just for Android.
So there's now Linux, there's now iOS, it's all pretty exciting.
Yep, so Android was first, and that was largely because
the Android development tools actually do run on Windows, so that was an easy target
to get the infrastructure up and to do all the prototyping.
And then iOS, we've started working on support. It's nowhere near complete.
We still have a lot of people working on it to make improvements in Visual Studio updates.
So we do quarterly updates to Visual Studio,
and so we'll continue adding new features and making bug fixes through those.
Okay.
Do you want to talk some more detail about this change you worked on with the Universal CRT?
Yeah, sure.
So I guess the short version is about, well...
Well, maybe to start.
I mean, what exactly is the Universal CRT,
and kind of what do developers working in Visual Studio need to know about it?
Okay, yep.
So I guess I could start with
a little bit of history. So back when Visual C++ 6.0 was released, it shipped with an msvcrt.dll,
which was the C runtime and contained the C standard library for Visual C++ 6. And Windows
actually depends on this. So most components in the Windows operating system depend on this DLL.
It ships as part of the operating system even through Windows 10.
And Visual C++ releases starting with the next release,
so Visual C++ 7, which would have been 2002,
included basically they each include their own CRuntime.
So there's an msvcr70.dll, an msvcr71.dll,
all the way through up until in Visual Studio 2013,
we had an msvcr120.dll for version 12.
And so we identified that there were a number of problems with this,
that the fact that we have a whole new set of libraries every release
makes it difficult for customers to build libraries
that work with different versions of Visual Studio.
So if you want to build one library that works,
that your customers can use from either Visual Studio 2012 or 2013,
generally you have to build two different versions of your library.
You have to build it once with Visual Studio 2012
and once with Visual Studio 2013 and ship them both to your customers. So we've heard from a great many customers that this is
a real pain point for them, that this prevents them from upgrading to newer versions of Visual
Studio. Oftentimes, they may have libraries that they can't rebuild, that third parties provided them in binary form, for example.
And so what we decided to do about two and a half years ago now was refactor the C runtime so that we could actually start updating it in place once again.
And so that project is what became the universal CRT.
And so basically, we're no longer going to provide side-by-side updates
like we have in the past.
So we have in Visual Studio 2012 we shipped msvcr110.dll,
and in Visual Studio 2013 we shipped msvcr120.dll.
Now there is one DLL, it's named ucrtbase.dll,
and for future releases we're actually just going to
make updates to it. So that refactoring that we ended up doing actually ended up largely,
you know, in some cases ended up being a complete rewrite to try and take, you know, this ancient
code, some of which is older than me, dating back to the mid to late 1980s,
and try and actually improve it, bring it up to modern standards,
and try and get it to the point where we could with confidence make changes to it
without actually breaking existing code.
Because if you build a DLL today, you still want it to work 10 years from now.
You don't want changes that we make to be breaking you.
And so we put a lot of work into that,
trying to, I guess, improve the maintainability of the library so that it was stable, that we could make changes to it going forward.
So as part of this effort,
we've also moved it into the operating system.
So now in Windows 10, it actually ships as part of Windows 10.
So if you install a clean Windows 10 machine and you look in the system directory, you'll see it there.
For Windows Vista through Windows 8.1, we have Windows Update packages that you can install.
It hasn't yet been pushed out broadly via Windows Update.
That's probably going to happen in September and October.
So it'll go out as an optional update, and then it'll go out as a recommended update the following month.
And so that'll get it onto most machines, which will help with the distribution point of view.
We still do support Windows XP.
We don't have a Windows Update package for that because Windows doesn't build Windows Update packages for Windows XP anymore
but we do have, if you install the Visual C++ redistributable
it'll install it on Windows XP or you can copy the binaries
locally to your app. It seems like XP was an extra checkbox when I installed
Visual Studio 2015 the other day, is that right?
Yes, actually. So I believe that that's been the case installed Visual Studio 2015 the other day. Is that right? Yes, actually.
I believe that that's been the case since Visual
Studio 2012 or 2013.
Oh, I hadn't noticed before.
Yeah, so by default, if you install
Visual Studio 2012
or above, it comes with the...
Well, 2012 comes with the Windows 8 SDK
and then 2013 and 2015
come with the Windows 8.1 SDK.
The Windows 8 SDK drops support for Windows XP,
so you can't use that SDK to build things for Windows XP anymore.
And so the tooling for Windows XP that you have to check the box for
actually just installs the Windows 7.1 SDK,
which does have support for building for Windows XP,
and it sets up a few extra things
in the IDE, so you can pick that. But it's the same Visual C++ libraries, it's the same Visual
C++ tools, it's just a different Windows SDK that you end up using in order to be able to support
Windows XP. So you mentioned deployment already, and that you're going to, it'll potentially be
pushed to through Windows Update. But today, like if I'm writing an app in Visual Studio 2015, I want to deploy it to a
computer that's got Windows 7 on it. What do I need to package with my application now with your
universal CRT to make sure it works? Yep. So our recommendation is to install the Visual C++
redistributable. So we have, it's called the vcredist,
because I think it's actually just named vcredist.exe.
And it's, you know, if you install that,
it will install all the Visual C++ retail libraries to the system directory,
and it will also now in Visual Studio 2015,
it will install the appropriate Windows update
containing the universal CRT onto your machine.
So basically, if you install that, it gets all of the files that you need onto the machine,
and you don't have to worry about anything else. So that's our generally preferred method for
people to use the libraries. By using the vcredist, it enables us to service things. So
if we discover a terrible security bug in the libraries, we can go out and we can actually patch it through Microsoft Update.
If you can't, for whatever reason, install the VC Redis.
So, for example, we have some customers who need to actually run their software on machines
where they don't have admin rights or they can't install for other various reasons.
You can actually take the DLLs and we provide them with the Windows 10 SDK
and you can just include them with your app
and ship them locally.
Now, the advantage of this obviously is,
yes, you don't need to have any installer.
You just stick them in your directory.
You can copy the files around wherever you want.
The disadvantage is that we can't service them, right?
There's no way for us to fix any bugs or security issues or make improvements to them.
Okay.
And going forward, if you're only targeting Windows 10 with your C++ application,
I guess the idea is you don't need to worry about that at all because it's already going to be on the system.
Yeah, so going forward with Windows 10, you'll still need to install the vcredist in order to get the – so there's other libraries in the VC Redist.
So the STL libraries are in there.
ATL and MFC is in there.
So in order to get these other libraries into the system directory, you would still need to install the VC Redist.
But for the universal CRT, you would not need to do that, basically. It's on the system, and if you install the vcredist on Windows 10,
it just doesn't install anything for the universal CRT because it's already there.
For over a decade, ReSharper has been helping.NET developers be more productive
and write better code in Microsoft's Visual Studio.
Starting this year, it expands the list of languages it supports
by adding a dedicated edition for C and C++ developers.
To put it simply, ReSharper C++ makes Visual Studio a much better IDE for C++ developers.
It provides on-the-fly code analysis, quick fixes, powerful search and navigation, smart code completion, automated refactorings,
a wide variety of code generation options,
and a host of other features to help increase your everyday productivity.
The list of things that ReSharper C++ can generate for you include definitions,
missing and overriding members, equality and relational operators, hash and swap functions,
add dozens of customizable templates, and you'll deal with boilerplate code faster than ever
code refactoring for c++ help change your code safely while context actions let you switch
between alternative syntax constructs and serve as shortcuts to code generation actions
with resharper c++ you can instantly jump to any file type or type member in a solution
you can search for usages of any code and get a clear view of all
found usages with grouping and preview options. Visit jetbrains.com slash cppcast dash resharper
dash cpp to learn more and download your free 30-day evaluation. And if you're a student or
an open source project, get your license for free, courtesy of JetBrains.
So you were just talking a bit about how you're updating all this code and some of it's older than you, and you actually did a talk at a...
You make me feel old.
You did a talk last year about this topic with modernizing Legacy's C++ code.
What are some of the lessons you learned
while going through this process?
Yes, I learned
to be very afraid. Wait, no, that's
not the lesson.
I actually, when we
started the project two years ago, I was
I guess I would say I was
very conservative with making changes, right?
We only made the bare minimum changes that we needed to to the code.
You know, after a few months of doing that, we had a much better understanding of what our test coverage is.
We actually have some enormous test suites that cover, you know, regression tests from all the releases from the past, you know, couple decades.
And then we have actual feature tests for, you tests for features that were written as they were implemented.
So as we developed a confidence that we actually had tests
that were going to help us catch regressions,
we started becoming a bit more aggressive
in making internal changes.
So actually, by the end of the project,
I would actually say we weren't afraid
to make major changes to most things.
There were still a few things that we were a bit wary of making big changes to.
For example, we didn't make a whole lot of changes to the locale library because it's a bit terrifying to look at.
That's evident if you look at the source code.
We actually ship most of the source code with the SDK, so you can actually take a look at the source code we actually ship most of the source code with the sdk so now you can
actually take a look at it um but yeah it was um um yeah in terms of lessons learned i think that
that's the the biggest thing you know was you know it took us some time to understand what kind of
test coverage we had and to you know to confidence that they were going to catch regressions.
And then once we had that, it was much easier for us to be much more aggressive in making changes.
Are there any types of patterns or refactoring methods that you could recommend after going through that process? Yeah, so the talk is online. Actually, it's online in two different places. I had given it previously at the Microsoft Tech Days conference in The Hague last April, and then Kate Gregory and I gave a version of it at C this year, though I don't believe that one was recorded.
So in terms of techniques,
yeah, it's hard to... This is like the guy who was asking about pointers earlier.
It's kind of hard to describe techniques
without showing code examples.
I would say that most of our...
Most of the refactorings that we ended up doing
was we would start with local refactorings. So we had a lot of functions that were many hundreds
of lines long, and they had huge amounts of indentation, and they were very hard to understand.
And what we'd actually do is we found it very effective to basically have a whole change set
where all we would do is we would make local refactororing. So we would not change any of the public interface,
so we would keep all the functions the same.
We wouldn't actually move things into their own functions.
We wouldn't redesign functions, change parameters, and things like that.
So we would just refactor the internals of individual functions.
Maybe we'd break some things out into helper functions or things like that.
But the important thing was any changes we made to a function
they wouldn't impact any external callers.
And so we'd make those changes
and we'd get them checked in and make sure they were good.
And then once we had a whole bunch
of fairly clean functions
but the interface wasn't quite what we wanted
we'd then go back through and make
global refactorings.
And so we'd take the
we'd redesign function interfaces and, you know, change parameters.
We'd move things into classes as we saw fit.
And so this, you know, one of the advantages that we found from doing this was that, you know, it was much easier to code review, right?
Because we could actually look, you know, when we had the local refactorings, we could actually look at it and we could walk through it and, you know, really understand that, you know, there were no global effects outside of the function.
And then we were doing the global refactoring, you know, we could focus really on the structural changes and there weren't a whole lot of logic changes within the functions.
And so I think that that was one of the most useful techniques, you know, that we followed with the refactoring.
Okay.
One of the things that we mentioned during your bio or during one of the feedback questions was
you did a course on Microsoft Virtual Academy
with Kate Gregory a while ago,
and this is kind of a general C++ course, is that right?
Yep, yeah, so that was actually the beginning
of Kate's and my collaboration.
That was almost two years ago.
We taught a full day.
It was live on the Microsoft Virtual Academy website,
and then it's available for anybody to go and watch for free on their website now.
And, yeah, so it's basically like an introduction to C++
for people who have some knowledge of programming.
So not for programming experts, but we're not going to explain this is what an if statement
does, this is what a loop does.
But we will explain the very basics of C++ and the important pieces.
It was probably one of the most challenging things I've ever done, both because of the
length.
Talking for an entire day all in a row
was quite difficult. But also, it turns out that talking about the basics is actually, I would say,
much more difficult than talking about, you know, very advanced topics. You know, if I go to a
conference, I'm going to talk about something really advanced, I can kind of assume that the
audience has a lot of background in, you background in at least something similar to the subject,
or at least I can talk technically to them and have them understand.
And with the introductory course, we had to explain the very basics of C++.
And as your feedback from the beginning had, it can be hard to understand, you know, pointers, for example. And, you know, for me, pointers are second nature, right? I've
been using C++ for a long time. And I'm, you know, any anyone who's been using C++ for a long time,
you know, understands the principles of indirection and how things work.
So, you know, it was a challenge from that point of view. But I think we ended up with
with a pretty decent course.
We actually, you know, we started off with the, you know, a hello world type thing.
Because it was for Microsoft, we showed, you know, largely in the Visual Studio IDE and debugger.
But all the actual code that we were writing was, you know, just portable normal C++.
We actually, you know, we tried a few new things. So one of the things that we did was we actually taught pointers after we taught classes and inheritance and references. So we taught all
of those things without having any recourse to pointers. And then afterwards, we explained,
you know, how pointers, you know, interplay with those things. One of the regrets I have from the course was we, this was, I guess, right after Visual Studio 2013
shipped, and I was really excited about brace initialization, which is a new C++11 feature.
And so we went and we used brace initialization everywhere all over the place in the course,
and we recommended that people use it. And, you long after that, we started to really understand that brace initialization
has a lot of problems.
There's a lot of very sharp corner cases that almost everybody will run into very quickly
if they try to use it everywhere.
And so I actually try not to use it anywhere now.
So that's somewhat of a regret that we ended up doing that.
But overall, yeah, I think the course ended up pretty good.
We've had a lot of people watch it.
It's in the tens of thousands.
I don't know what the exact number is off the top of my head.
But yeah, so it was a lot of fun.
Is the target audience kind of getting C Sharp developers
who've never touched C++ interested in it?
I don't know what the Microsoft Virtual Academy's target audience was.
Our target audience was basically to just get anyone who was interested in learning the basics of C++.
I feel like I need to keep a link to this around for people who ask questions.
It's very well reviewed, by the way, I see on the Microsoft Virtual Academy website.
Yeah.
Five stars.
Well, I keep going there every once in a while to give another five stars.
That's a joke.
Your Microsoft bonus is in no way tied to how many stars that gets.
I hope not, but I'll have to double check with my boss.
And just for listeners who might not have ever heard of Microsoft Virtual Academy,
that's a completely free resource, right?
You don't need anything to go watch that.
Yep.
I don't even know that you need to log in.
It doesn't look like it.
Yeah.
I think you can just go and watch the videos.
Very cool.
So, yep.
Okay.
Well, is there anything else you want to talk about,
about Visual Studio 2015 or other C++ topics before we let you go?
I actually have a question about the universal runtime still.
Absolutely.
So you said that basically the point is that
you can make a library that will work on more than one version
of Visual Studio now, right?
That's fundamentally the point?
Or one of the points?
Well, so there's a caveat to that. And that is that the only piece of the Visual C++ libraries
that we've actually, you know, refactored to this point is the C runtime. So we haven't
done any work to the STL or, you know, other Visual C++ libraries. And so if you use those, you're still, you know, going to be tied to a particular version of Visual Studio.
And maybe even worse, you may be tied to a particular version and compilation flags.
So that's kind of the project that I'm heading up for the next release is to look at the rest of our libraries
and figure out what, you know, what can we do to fix that.
The C runtime was a bit easier than the STL because the C runtime,
most of the exports were already C exports. So C exports are fairly easy to work with.
Whereas with the STL, we have, for example, IO streams, which is just one tangled ball of
functionality. And trying to disentangle that into a way that we can maintain it long term
is going to be a bit of a challenge.
Yeah, I mean, when you brought it up, specifically what I thought about was the download page
for Boost has, I don't know, four different downloads for each version of Visual Studio
since the beginning of time or something.
It's a lot of different configurations to manage.
So I was wondering how you dealt with some of these C++, those kind of issues like template
things. It seems like something that you would need C++ modules for whatever that hasn't yet
been standardized. Yeah, so we haven't really tackled the C++ piece of it yet. And long-term, we probably won't.
Long-term, having C++ interfaces between binaries
is not a particularly maintainable solution.
Actually, at CppCon last year,
Stephanus Dutois gave a talk called Hourglass Interfaces.
It was a really great talk about how you should use
the best modern C++
practices within your library. And then you should expose your library, you know, if you're
implementing a library in a DLL, you should expose it as, you know, as a pure flat C interface. And
then you should write, you know, a great rich, you know, modern C++ API surface on top of it
that's in the headers. And so basically, you know, the idea is you use C++ within your library
and within the headers where people are going to, you know, actually consume it,
but the actual interface between your DLL and, you know,
any other code that's going to be using it is all pure C.
And so there's a ton of advantages to this.
It's much more maintainable.
It makes it much easier for you to understand, you know,
what the actual API surface is so that you don't accidentally make any breaking changes.
It makes it much easier to use your library from other languages because almost any language can call into C,
whereas calling into advanced C++ constructs from another language can be quite tedious and difficult.
So it was actually a great talk.
I'd highly recommend it to anybody who's trying to
build reusable libraries of that sort. That sounds interesting.
Yeah. And a lot of those techniques are kind of what we're looking at for the rest of our libraries.
Okay. Okay. So the universal CRT work is just kind of the first step in a longer, bigger plan.
Yep. Okay. So James, where can
people find you online if they want to see more of your stuff or just
see what you're up to? So I occasionally post lame
puns and things to Twitter. So it's
my Twitter account name is very creatively my real name. So I
should be fairly easy to find on there.
Like we said earlier, I post on Stack Overflow occasionally.
I keep a fairly close eye on the Visual C++ tag and other things like that.
But Twitter is probably the easiest way for people to get in contact with me
if they have any questions or want to know more about something.
Very cool.
Well, thanks so much for letting us have you on the show, James.
Hey, so before we go, I actually have one more thing.
Sure.
So my team, the Visual C++ Libraries team, is actually hiring right now.
We are looking for great C++ software developers
who want to come and help us make our know, make our awesome libraries more awesome.
Or, you know, if you think our libraries are terrible,
then we'd like to talk to you and, you know,
we'd be interested in your help to, you know,
come and make our libraries less terrible.
So, you know, we are looking for people.
People are welcome to contact me directly, again, via Twitter or email.
Or we can share, you can share the job posting.
So, yeah.
Should they just go to, what is it, Microsoft.com slash careers, look for C++?
I can share a link that we can include in the show notes.
Yeah, I think if you just search for Visual C++ on there, I've tweeted the link a couple times.
Okay. Very cool. We'll make sure tweeted the link a couple times. Okay.
Very cool.
We'll make sure to share that with the listeners.
Excellent.
Okay.
Thanks so much for giving us some of your time.
All right.
Well, thank you very much.
Okay.
Have a good one.
You too.
Thanks so much for listening as we chat about C++.
I'd love to hear what you think of the podcast.
Please let me know if we're discussing the stuff you're interested in,
or if you have a suggestion for a topic.
I'd love to hear that also.
You can email all your thoughts to feedback at cppcast.com.
I'd also appreciate if you can follow CppCast on Twitter
and like CppCast on Facebook.
And of course, you can find all that info and the show notes
on the podcast website at cppcast.com.
Theme music for this episode is provided by podcastthemes.com.