CppCast - Jumping into C++
Episode Date: February 15, 2017Rob and Jason are joined by Alex Allain from Dropbox to talk about Dropbox's Djinni code generator and Alex's book Jumping into C++. Alex Allain is a Director of Engineering at Dropbox. He was... one of the first engineers on the Dropbox Business product before leading Dropbox's Product Platform group, whose initiatives includes the Dropbox Sync Engine, shared mobile C++ and developer tools. Alex has run Cprogramming.com since 1998 and is the author of Jumping into C++, a book for new programmers. News CppChat: The Great Functor Debate (Ben, Jackie, and Jonathan) Monads in C++ COMMS Library Undefined behavior in C and C++ programs Alex Allain @alexallain Links Djinni CppCon 2014: Alex Allain & Andrew Twyman "Practical Cross-Platform Mobile C++ Development" CppCon 2015: Jacob Potter & Andrew Twyman “Bridging Languages Cross-Platform..." Djinni in a bottle - Easily share code between iOS and Android using C++ by Stephan Jaetzold nn: Non-nullable pointers for C++ mypy: Optional static typing for Python 2 and 3 (PEP484) cprogramming.com Jumping into C++ (Amazon) Sponsor Backtrace JetBrains
Transcript
Discussion (0)
This episode of CppCast is sponsored by Backtrace, the turnkey debugging platform that helps you spend less time debugging and more time building.
Get to the root cause quickly with detailed information at your fingertips.
Start your free trial at backtrace.io.cppcast.
And by JetBrains, maker of intelligent development tools to simplify your challenging tasks and automate the routine ones.
JetBrains is offering a 25% discount for an
individual license on the C++ tool of your choice, CLion, ReSharper, C++, or AppCode.
Use the coupon code JetBrains for CppCast during checkout at JetBrains.com.
Episode 89 of CppCast with guest Alex Delane, recorded February 15th, 2017.
In this episode, we discuss undefined behavior in C++.
Then we talk to Alex Delane,
director of engineering at Dropbox.
Alex talks to us about Genie and hisast, 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?
All right, Rob. How are you doing?
I'm doing good. It's been a busy week. It was actually my son's birthday today.
He turned eight today and had his birthday party this past weekend.
Lots of Pokemon stuff all over the house. Good times.
A house full of kids running around?
House full of kids running around house full of kids running around
because it was a pokemon themed party everyone got him pokemon cards so he's got more cards than
he could ever possibly use good wow yeah that's cool yeah at the top of every episode like three
to piece of feedback uh this week we got a tweet from rob cherry we actually got a lot of feedback
from last week's episode jason uh but this tweet said listen to the stl episode of cpp cast last night definitely my
favorite episode so far good show i was actually looking at this um at rob cherry's profile
and he works at blizzard with our friend ben dean on the server team that That's cool. Yeah. And, uh, speaking of Ben, did you watch the,
uh,
CPP chat episode last weekend?
No,
I did not get to it.
Oh,
okay.
Cause he,
Ben Dean was on that along with,
uh,
Jackie K and John and,
uh,
Jonathan Mueller.
Uh,
we gave them a little plug last week,
how they're going to be talking about,
um,
Jackie's functor article.
It was definitely
worth watching yeah and by the way i was gonna say i'm happy to say i i don't feel embarrassed
for not understanding some of the uh more complicated aspects of jackie's article
because uh jonathan uh john cobb also said a lot of it went over his head.
Well, I was going to say, I've heard from several people that the STL episode was their favorite so far also.
Yeah, we got a lot of great feedback and I would love to have him on again.
I think there were a lot of questions we didn't even get around to asking because the interview
got to that hour time stamp.
But yeah, we'll definitely have to get him back on.
Yeah.
Yeah.
Well, anyway, Rob Cherry, we're going to get him that JetBrains giveaway that we mentioned
last week.
We're giving away licenses to one of the JetBrains products.
So we'll get him in touch with Anastasia from JetBrains.
And we'd love to hear your thoughts about the show as well.
You can always reach out to us on Facebook, Twitter, or email us
at feedback at cpcast.com.
And don't forget to leave us a review on
iTunes. Joining us today
is Alex Allain. Alex is
a director of engineering at Dropbox. He was
one of the first engineers on the Dropbox
business product before leading
Dropbox's product platform group,
whose initiatives included the Dropbox
Sync Engine,
shared mobile C++ and developer tools. Alex has run cprogramming.com since 1998,
and is the author of Jumping into C++, a book for new programmers. Alex, welcome to the show.
Thanks for having me. I'm excited to be here virtually, I guess.
So is the Dropbox Sync Engine just like that thing that we think of that uploads the files to Dropbox whenever we copy them into our drive?
That's exactly right, yeah.
When you put it that way, it sort of makes it sound easy,
but it turns out to be one of the really, really hard things to do in the Dropbox product.
Sometimes people ask, is it, you know,
a UI on top of our sync? And I mean, sure, like we're syncing files, but getting it right,
especially at scale with, you know, tens or hundreds of thousands of files and doing that
fast across a bunch of different operating systems is pretty tough. It's one of the
most interesting parts of our code base, you might say.
I imagine also dealing with the fact that multiple clients can be touching the same
files is difficult.
Yes, yes.
Handling those kind of races, you know, conflicted copies are a big challenge.
You know, two people editing a file, one person saves it, they're offline.
The other person saves it, they're offline.
They both come online.
How do you handle it?
It's not easy.
Sure.
As you can imagine.
Well, Alex, we have a couple articles to go through.
Feel free to comment on any of these,
and then we'll start talking to you both about Dropbox and your work there
and also about
uh teaching new developers c++ sounds good sounds great okay uh so this first one is an article on
monads in c++ and uh we've been seeing a couple articles like this lately right jason covering
this one specifically covering uh stood optional and monads in general monads and
functional concepts seem to keep coming up yeah uh so did you understand the article rob uh a little
bit can you tell us what a monad is now i i think i understand the the simple case of monads as far
as optional or or you know kind of the nullable types are but i probably don't
fully understand monads yeah okay i know i don't it's sometimes called the maybe monad that's
another way to describe the optional right uh yeah sure that's what's used in this article
do you have a chance to look through this one uh Alex? I did. You know, I have this observation, speaking of understanding monads,
I have this observation that, like, basically, like, most of the articles that describe what a monad does
eventually describe it in terms of Haskell concepts.
And I have a confession.
Unlike all the cool kids, I don't know Haskell.
Maybe we should edit that part out later.
But, you know, I don't find it illuminating to go from the concepts.
Like, I'm not trying to learn Haskell when learning about monads.
So I never find it real illuminating when people hearken back to that.
And one thing I liked about this article is it actually, like,
talks about what a monad is
before doing that, like in a more general context.
But my personal beef with the like description
of monads community is it's almost always
like helping you understand a language you don't know yet.
And I find that tough.
Like one of the things that I love about folks
like Scott Myers is like they figure out
how to boil it down to like exactly
what I need to know to write the code and
the language I'm writing it in
and that
that's my rant on monads
I'll stop there
yeah I definitely think
Scott Myers books will be missed
as we keep getting new versions of
C++ we'll be ashamed
to not have his take on all of those new features coming down the pipe.
Yeah.
As we get further from his retirement.
Yeah.
Yeah.
You know, you mentioned that you didn't know Haskell, and I had completely forgotten that
I had actually gone through the first few chapters of real world Haskell and written
blog articles on them several years ago,
completely passed my mind until I was like looking through my old articles on
my website.
Oh,
wow.
I don't remember a bit of it.
Okay.
Uh,
this next one is comms champion and it is a protocol buffer library
specifically developed for the embedded community.
And it seems like the type of thing that some of our past guests
who talked about embedded development would be very interested in.
It's built for C++11,
and it's a very template-friendly embedded library
made for programs that might be running directly on bare metal.
Did you have a chance to read through this one, Alex?
This one's not in my wheelhouse, so I don't have a lot to comment on here.
How about you, Jason? Do you have a chance to look at it yet?
No, I didn't manage to get to it, unfortunately.
But I can imagine it would be interesting to get someone like Odin's take on it,
since that's kind of a specialty yeah
okay and then this last one is undefined behavior in c and c++ programs and this is a very long
article that kind of goes in depth of this programmer and his experience undefined behavior
both on a kind of a personal level but some of the problems he's seen over his career and
how learning about and understanding undefined behavior
has helped him as a programmer and can help others as well.
And I thought it was pretty useful
just to understand kind of why we have undefined behavior
in C++ and C compared to some other languages.
What did you guys think on this one?
I think it's a pretty important article
for c++ developers to read honestly and i love the uh sound effects that he put in here straight
from old school batman blammo kapow bang i was wondering what you meant by sound effects for a
moment you mean the comments yeah yes yeah i just want to jump in. I really love this article. I thought it was extremely clear and well written. And one of the things that I appreciated, you know, sometimes you sort of see these like cases where the compiler optimizes out this incredibly important check and it introduces some security vulnerability or whatever. And it's like, why would you do that? And this article sort of helps you sort of get your head around a around a little bit like hey why might that be a reasonable thing for the compiler to do right um and so and i just
really liked the clarity of it i you know sent the author a note uh actually i think it's a she
um but uh just uh told her that it was really fabulous and uh i was impressed yeah okay well alex let's start talking
um first i actually wanted to ask about dropbox and genie because uh when we first uh got introduced
to you after we started talking about wanting to have someone on to talk about um you know
new developers uh learning c++ uh i realized that you were working at Dropbox
and you gave one of my favorite talks at CppCon 2014
where Genie was introduced.
So for listeners who haven't heard of that,
could you maybe tell us a little bit about Genie
and let us know if any updates have been made since that CppCon talk?
Yeah, absolutely.
So the context here is Genie is effectively a code generator for generating bindings between languages.
So the first use case was basically generating all of the JNI code to communicate between C++ and Java on Android.
And so the idea behind Genie is you write an interface definition file,
you run Genie, it spits out both sides of the interface,
does all of the marshalling and unmarshalling and all of that.
Similar to something like Swig, but we think it's nicer.
And the motivation for Genie was we were working on a number of applications internally where we wanted to share logic.
And on the desktop, we use Python.
And sometimes that surprises people.
We can talk more about that if people are interested.
But on mobile, the best choice that we can come up with for cross-platform is C++. But we wanted to be able to share the same APIs so that people
building the UI layer in Objective-C or in Java wouldn't have to think about bridging between
languages. And so the purpose of Genie is to solve that language bridging problem for you.
And you can check it out. It's open source, DJI NNI. It's on the Dropbox GitHub.
And so in terms of updates, you know,
we haven't made a ton of updates over Genie in the last year.
We do have experimental Python support.
That was an intern project a couple years back for someone on my team.
And we don't actually have any current plans
to sort of like push that all the way to the finish line.
What would motivate us to do that primarily would be using more shared libraries on the desktop client where we'd want to be able to share it across mobile and desktop.
And that hasn't, as it turns out, just hasn't been a major priority for us.
But, yeah, we still use Genie.
You know, it's particularly good for like shared libraries and things where you just don't want to write things twice.
And of course, if you're writing your whole app in C++ on mobile and you want to have a UI layer, it can really help a lot.
Go ahead, Jason.
Since you brought up Swig, how do you compare it to Swig then?
You said you think it's better.
Let's dig into that.
Yeah. Let's dig into that. Yeah, so as a disclaimer, I'm not an expert on Swig,
but generally speaking, my understanding is sort of the primary way you use Swig
is to sort of annotate existing C-like code to make it callable from other languages.
So you've kind of got this existing interface
that then you're just doing the bare minimum to bridge the language gap.
And Genie sort of has this principle that, you know,
your interface should be written in the Genie IDL in a clean way.
We support some really nice programmer ergonomics.
So, you know, if you have an array list in Java on one side of your interface,
that's going to show up as a vector of whatever you have, you know, on the other side.
And so the programmer doesn't need to do a lot of extra work
when passing things around that are more complex types.
It just works, as we like to say about Dropbox in general.
This means there's a little bit more copying, obviously,
but the feedback we get from folks is it's really nice.
The other thing is that emphasis on the interface
being something that you really think about and create
rather than tacking on bindings to something
that's been written in another language.
I think you can create interfaces in Swig.
To be honest, we didn't know about that
when we first started working on Genie.
But we still sort of prefer the Genie model. We think it's a
lot cleaner in general. Yeah, you can either directly parse your header files or provide
an interface, but it's not a distinct IDL. It's still kind of a C++-like thing that you pass it.
Right. So you said that it started with Android and JNI. I guess you added the Objective-C and iOS support later.
I know you didn't mention Win32
or C++ CLI.
Have any third-party open source developers
ever thought of contributing to Genie?
And do you accept contributions
from open source developers?
Yeah, great question.
So I don't think we've had anyone
who's made any changes that are that large,
but we do accept open source contributions.
I think on GitHub we're at about 35, 38 committers total.
Probably most of them are external.
And we've had a few folks making pretty large changes.
Trying to remember some of the big ones,
but it's been a little while since we had a really major set of changes there.
But yeah, it's open source.
And so if somebody is excited to go and add support for, well, if they want to finish Python support, the good first one to work on, we'd certainly be excited by that.
So now I'm curious, does Dropbox have other open source projects that you've been involved with?
We have a number of open source projects.
You know, the ones that I've been involved with have been more on the C++ side.
So we have another library.
It's pretty small.
It's called NN for non-nullable.
And it's basically a non-nullable pointer type.
So you can, you know, basically, it allows you to have like an end of
a shared pointer, for example, and then you have a guarantee that it's never null. And so when you
take you ingest your pointer, you have to sort of do a check and say like, yes, this is
we promise like, honest to God, it's not null. But after that, you have the type system enforces this
for you. It's a pretty small library but um it's something we
think is pretty cool we've used it a lot in our c++ code to make it safer and if i remember
correctly i think jacob potter who's the author of that uh did a talk at cpp con 2015 i believe
so that might be something to check out we also also have a bunch of other open source projects.
We've open sourced a number of, we use Go as well internally.
We've got a number of Go projects
and trying to remember some of the other big ones.
But, oh yeah, one of my favorite projects.
This one is actually open sourced
under the Python community GitHub, but it's called MyPy.
And it's a static type checker for Python.
So PEP484 introduces a syntax for providing annotations to functions and to provide type annotations.
And so we actually have a team at Dropbox that's working on building support for that into MyPy,
which I think is another really cool project
that we're working on.
So that's interesting.
Is that kind of like a progressively typed
or partially typed thing,
or would you have to do fully typed
if you went down that road with your add-on?
Great question.
Yep, it is an incremental typing or partial typing.
And the type system has this notion of if it's not typed,
it has a special type that's consistent with other types.
So it's very easy to add a type somewhere.
And as long as you, if you haven't annotated your other code,
it'll continue to work.
If you do annotate that code and there's a conflict,
it'll suddenly tell you, hey, there's a conflict. And you can also do things, I believe
we have a mode where you can run it that says, like, don't allow that special type to exist,
so that you can have full typing if you if you want to. Oh, gradually type. That's the that's
the right term. Gradual typing, right? Like TypeScript does? Yes. One more question about
Genie before we move on.
Do you have any sense of how many other application developers might be
using Genie? Because I know
when we talk about cross-platform
mobile, unfortunately
C++ is usually kind of an afterthought
in the general programming community.
Usually people are talking about JavaScript or
Xamarin, but
we as C++ developers think it's great,
and these tools like Genie and Swig definitely make it easier.
Do you have any idea of how many apps are using it?
I don't know the number.
We've got a pretty large number of people starring Genie on GitHub.
It's maybe 1,400 or so, so it's not super small.
And I did a Google for genie recently and there's definitely
folks who are writing tutorials on how to use it and um so i in a couple of different companies
uh i believe i believe slack may be using uh genie actually and i think we've we've heard
about a few other companies but uh I don't know the full list.
Okay.
I'm curious what it would take to go from an existing code base to Genie 2, if that would be a lot of technical debt to go over.
Yeah, I think that it's definitely one of those things where you have a new way of doing something.
And so it's going to clean up a lot of your code.
We did have a bunch of hand rolled stuff
before Genie existed.
And so we sort of had to gradually replace it.
You feel a lot better at the end of the day
because a lot of like,
like any code generator,
you've got all this crap that is probably works,
but it's 20 lines to move like a string across languages and you don't feel great about those kind of things.
Sure.
I wanted to interrupt this discussion for just a moment
to bring you a word from our sponsors.
Backtrace is a debugging platform that improves software quality,
reliability, and support by bringing deep introspection
and automation throughout the software error lifecycle.
Spend less time debugging and reduce your mean time to resolution
by using the first and only platform to combine symbolic debugging,
error aggregation, and state analysis.
At the time of error, Bactres jumps into action,
capturing detailed dumps of application and environmental state.
Bactres then performs automated analysis on process memory and executable code
to classify errors and highlight important signals such as heap corruption, malware, and much more. Thank you. modernize their debugging infrastructure. It's free to try, minutes to set up, fully featured with no commitment necessary.
Check them out at backtrace.io
slash cppcast.
Okay, so we also mentioned
cprogramming.com in your bio, which I'm
sure all of our listeners have landed
on at some point during their career
when googling for an answer or something.
Can you tell us a little bit about the website
and how you got started running it?
Yeah, absolutely.
So cprimary.com has been around since 1998.
But actually, the original content started,
I started writing in 1996.
And, you know, to be honest,
when I first wrote the site, I was in middle school.
So I was actually still learning how to program at the time.
I apologize to anyone who was learning back then and maybe got an article or two that weren't quite accurate.
But I find that I personally learned really well by writing.
And there were a bunch of good programming sites on the Internet even back then.
And it sort of inspired me to say, like say like hey people are actually interested in this stuff i think i can write about as well as as
these folks and it helped me a lot to get understand the concepts and um i think it's
actually helped a ton of people and one of the things you get when you do this is you get um
you you have empathy for the the person who's starting out. And I think a lot of times it's really easy to get lost
in all of the complexities of the language
and not focus on the really core stuff
that just beginners don't have the basic concepts.
And the site's gone through a ton of evolutions.
I've rewritten almost all of the content,
I think two or three times now. And I'm very happy with where the C and C++ tutorials have landed,
although the real, true, final version of those tutorials is jumping into C++, my book.
And the goal that I had when I wrote that was to go from a series of individual disconnected articles to
something that was really a holistic, I'm a new programmer, I don't want to have to look everything
up in different places, just take me through the whole journey of going from, I don't understand
how to program to I can make a computer go and do stuff. And so, you know, the site's evolved a lot. And for me, the core of the site has always
been those couple of tutorials and wanting to make that better. It's got a bunch of other content on
it. Because as I've, like I said, when I learn things, I really like to write about them. So as
I've gotten into different areas, I've written a bunch of tutorials in those spaces, I'm particularly
happy with the C++11 tutorials that I wrote. And then we have a message board with a pretty
active community as well that's been fantastic. You know, many, many people over, I think,
almost the entire lifetime of the site now have been participating. And it's really cool to see
those kind of communities spring up and have people who've been working, working to help teach other programmers for, you know, 15 or 15 or more years.
Wow. Well, you just mentioned your book, would you like to talk any more about that?
Sure, you know, I think that so I have a very strong opinion about how I like to learn. And it is I like to get a book that takes me through all of the topic in a way that is is thought through and consistent and coherent. like there was an opportunity to write something that really took people holding their hands enough to really understand things, but that was really also pretty comprehensive and covered a lot of the challenges that I think really scary for a lot of people.
I introduce pointers with, don't worry, it's okay.
I'm sure you've heard they're scary, but I'm quite confident you can learn it.
You can have all of the technical bits you want, but I think there is a little bit of that human element as well.
I am a reader trying to learn this thing that's
hard. Like, please make me feel like I can actually do it. And so I, the book brings a
little bit of that as well. It tries to be more, um, have a little bit more of a personality than
maybe some drier technical books do. I mean, it's, there's only so much you can do to make
writing about programming, like feel like a novel, but, like a novel. But I did try to get some of that across.
And I'm really happy with the book.
I think it's a great way for people to learn C++ if they're a new programmer.
The truth is it's really optimized for new programmers.
So most of this audience is probably not going to get a ton out of it.
But if you are somebody who's just getting started with C++, it might be a great way to learn.
The other thing is, it's definitely intended for people who haven't programmed before. So I try to
cover a lot of material that might show up more in like an introductory class that I think is just kind of good to know.
How do data structures work?
How do you actually think about writing an algorithm?
One of the hard parts for a new programmer is just,
I don't know where to start.
I've got a blank text file
and I need to turn it into something that'll do a thing.
Like, how do I break that down?
And so the book
tries to take people through some of those things that might be missing if you're just learning C++,
but you're already an existing programmer. So do you have you been updating it as the
standard evolves? Do you have plans to update the book for C++ 17? Great question. So the short
answer is this is a dream that I would like.
I would love to update it.
Just a bit of history.
I published it in 2012 right after sort of, you know, sort of C++11.
And at the time, I actually, the book does not cover C++11.
And the reason for that was very intentional, which is the time the compiler uh support was just not there
and one of the worst things you can do like there was actually let me be clear there was definitely
good support for people who were expert c++ programmers and knew their way around to find
the list of supported features and know this should work, but this won't work.
But if you're a new programmer, you don't want to go through that experience.
It's already hard enough to get up to speed without having to figure out that, oh, shoot, my compiler doesn't support, you know, range for loops or auto or whatever, or like even worse,
like some obscure edge case of something like that. And so I was very intentional about not trying to get fancy.
The truth is, today, the support's really good.
And if you look at some of the features there,
I think that for a new programmer, auto is really nice.
Like, when you're getting into learning about variables,
you can sort of eliminate one step in the process
to get somebody the basic
idea of, I can put a thing in this thing, and then you can introduce types a little bit later,
potentially. I'm not sure if that's the right way to do it, but it allows you a little bit more of
an incremental flow that's less concepts being introduced at once, which is nice. Things like
range for loops can simplify iteration over a vector, for example.
So you can maybe introduce vectors earlier without having to introduce all this crazy syntax for an iteration that a new the idea of taking advantage of a lot of the newer
stuff to to be a better on-ramp for new programmers but the truth is i i have a pretty active job so
i don't have a ton of time to sit down and uh and do it um so i guess you wrote the first uh book
before uh joining dropbox that's right yeah so i wrote it in the the two years before joining Dropbox? That's right. Yeah. So I wrote it in the two years
before. Actually, one thing that's interesting about how I wrote the book that I would like to
share, because I think this is potentially something that other people might find valuable.
I actually wrote the book in a way that was very incremental. So I worked on it every day
for that two years for about 10 minutes. And I would write
down how long I worked on it so I'd have some sense. And the key idea there for me was when
you make progress every day on something, you'll eventually get there, even if it's really slow.
And if you do it every day, you're in the headspace of the ideas that you're working with.
So it's not like I wasn't thinking
about the book for maybe, you know, my drive to work or my ride home or, you know, talking about
how do I write this out and describe it in the right way with my friends or my girlfriend or
something like that. But, you know, doing it every day was just forced me to always be thinking
about it and always make progress. And I think that's also something that can be really valuable for people who are learning to program.
It's just like force yourself to write a little bit of code every day.
And by the end of a year, you'll have written like a lot more code than if you do it for a weekend or two.
That's cool.
On your bio on cprogramming.com, it mentions that you taught introductory C and C++ courses at Harvard, I think.
I was wondering, do you approach teaching C++ differently than you would teach C?
Great question.
So, yeah, let me talk about that a little bit.
So when I was at Harvard, one of the things I did was basically being a teaching fellow.
It's a collection of folks who help the professor teach
the class. And there are two classes, CS50 and CS51. And so CS50 is all C from end to end.
Back in the day, it's actually changed quite a bit. If you go to like cs50.net, you'll see a
pretty different class these days. But when I
was doing it, it was all C. And then CS51 was Scheme, C++, and Java. And so the approach was
pretty different. Like in CS50, we were focusing on get people to understand how to program the
basics of programming, and start to get them sort of the conceptual model of how a machine works. So you want to make sure that people get pointers, arrays, what does it mean to scribble
off the end of an array, going back to the undefined behavior article, making sure you teach those kind
of things to people early, and focusing a lot on kind of the basics of programming.
And then in CS51, it was much more a tour of languages.
And so the truth is, we didn't get that deep into C++ itself.
A lot of the object-oriented concepts came about with Java.
But I will say, one thing that was really interesting,
this is not exactly answering your question,
but it just struck me every time we saw it.
We do scheme first at the beginning of the year.
And people would do all these really cool programs
after like one or two weeks.
They'd write a Markov babbler.
They'd do graph coloring algorithms
with recursive backtracking and things like that.
And then we'd get to C++.
And this was the thing that made me really sad.
We'd hit C++ and people would just take so much longer to write really basic stuff
because there was so much more complexity in the language.
And you write out a template, and you put in the wrong argument,
and you get a three-page error message.
And it's like, oh, my goodness.
And so this sort of inspired a little bit in jumping
into C++, sort of trying to take people very gently through some of these challenging parts
where they would end up seeing just things that beginners can't easily understand. And I'm excited
for things like concepts to maybe help improve the error messaging here. And just even better, I mean, this was a long time ago, you know, tools like Clang,
I think have better error messaging at this point as well. But it was a really interesting gap that
I saw. And definitely, even like with folks who'd taken CS50 learning C, the compiler error messages were just like, seemed easier for people to understand
and sort of work through. And it was a challenge, I'll put it that way. Whereas in C, it was easy
to focus on the basics. In C++, the truth was, we were also trying to teach some of the more
advanced concepts. So you're sort of getting this like scheme to C++,
assuming you knew C.
But yeah, to me, like this is one of the challenges with teaching people C++.
So is there anything in particular
that you would like to call out
that trips up new C++ programmers
that you think maybe we could do a better job of teaching?
Sure, yeah.
So the truth is, even before C++, the language,
I would say that getting set up is really a big hurdle for people.
You know, in jumping into C++,
a lot of the time was spent just figuring out,
like, okay, how do I make sure that people can get a good environment set up
on all the platforms? You know, if you're using Windows, if you people can get a good environment set up on all the platforms,
you know, if you're using Windows, if you're on a Mac, if you're on Linux, and making sure that
people would not get tripped up before they even got off the ground. And, you know, to some degree,
this is just always hard. And there's, there is just some work, I think that it's awesome that people have started putting online compilers
that you can run in a web page.
I think Go has done a fantastic job of this with the Go tutorials,
and you can sort of walk through that online
and build the program without almost much setup at all.
And so that's a direction that I'm really excited about. When I wrote the book, that was a much less common thing. But I think getting
people set up in a long term, like way that you can write programs and is not so easy. And
the other part of it is understanding the the compilation model and sort of how everything works
takes a while.
It's important to
try to give people the really basic
cookbook of here's how to
create a file,
put these things in it.
Don't try to get too fancy until much, much
later because otherwise it's
just very confusing.
I think I want to put in that one plug for just empathy
for the basic beginner setup of installing software that lets you do work is one.
Another thing that I found very awkward when I was writing the book
and really trying to explain things is the fact that operator overloading features
in the very first C++ program anyone will ever learn. Like you're teaching people about output and it's like,
see out, arrow, arrow. And it's like, this is not a concept that applies anywhere else
in what you're doing. You know, everything else, you've got function calls. So it's kind of awkward
when you introduce functions like one or two chapters later and it's like different from what you were doing before
i don't think that that's an incredibly big blocker for folks but it's it's awkwardness
that i think is a little bit unfortunate um and another area that i think is hard and it's easy
to sort of get lost in if you're teaching c++ to a new person. As I mentioned earlier, just developing intuition for how to think about algorithms.
Like when I wrote the book, this was like the last chapter I wrote because I sort of forgot about it.
And then I realized, hey, if I'm a new programmer, none of this helps me if I can't figure out just
how to put together the step-by-step, make a program, do a basic thing.
And so it's easy to think about C++ as having its own,
you know, it's got a lot of features,
but really for new programmers, in my opinion,
a lot of it is just the really basic stuff.
And then I would say the last two really clear things,
like pointers are always really hard for new folks.
And I have sort of a story about this from my own life.
So I originally learned C before C++.
And the book that I was reading described it in a way that I came away thinking that the purpose of pointers was to scroll text across a screen.
Because that was like the example that they use. And obviously, that doesn't make any sense. But I think it's really hard to get the why behind pointers. When you're a new programmer,
you don't really have a sense for like, oh, memory is this thing that you have to use to build data
structures. And you can't, you know, without pointers, it's hard to get more than a fixed
amount of it. And why would you even want more than a fixed amount of it? You know,
all the programs you've done so far don't need more than a fixed amount of memory. So it's really
hard to motivate that. And in the book, I tried to motivate that by giving examples earlier in
the book that sort of pushed on the like, hey, don't you kind of wish
you could have extra memory to solve this problem? And you could kind of do it by creating a long
arrays or whatever. But I think that the motivation and the why is actually a pretty tough part of
pointers. There's obviously the indirection and really getting the syntax right. And there's all
those little details. But if you don't understand why you're doing it, it's much harder than it needs to be. And I think that that also comes up when you're
teaching people things like classes and polymorphism. You know, it's, again, really easy
to get into the sort of the abstract, like, why this exists from good software engineering
principles. But if you're a new programmer, software engineering principles aren't your problem. At the end of the day,
it's much more understanding how to get a computer to do something interesting.
And it's not that easy to get a simple description. So again, I think getting to the underlying why
behind it and giving really good examples is pretty hard. You know, I think
it's one of those things where, you know, if you explain things in terms of like, hey, you have
like a class hierarchy with shapes or whatever, it's like, that doesn't help me understand why
I want classes. If I've got like shape and then I have a subclass that's a square and another
subclass that's a rectangle, like those kinds of teaching styles are easy to fall into, but I think not very clear.
Um, versus, you know, you want to be able to have this function that can operate on,
that can behave differently based on different inputs.
And so you have polymorphism to allow that to, you know, to happen.
Um, so those are, those are things that I think really trip people up.
Um, and I would say the biggest, if I were to boil it all down, there's two things.
Three things.
One is setup.
Two is thinking about how to go from nothing to something.
And then the third is explanations that really boil things down to the underlying why in a way that somebody who doesn't have a ton of existing context
can appreciate.
And so that usually means giving some really good examples.
But those are things that I think often trip people up.
It's interesting that you mentioned the setup
because I don't think that came from the book
when I learned C++.
I'm sure the instructor told all the students
how to go about setting up their compiler and everything,
but I don't think that came from the book.
So I take it you explained it, pointed towards a compiler that they can use,
and you actually encourage using actual code examples as they go along?
Oh, yeah, yeah.
So this is one of the things.
If you have a class and an instructor, then that's awesome because you don't have to
worry about that but for a lot of new folks i think a lot of folks who end up reading jumping
into c++ or hitting c programming.com they don't they either don't have a class that they're
learning from they're very self-motivated learners which i think is awesome or they may have a really bad lecturer. And, you know, it's not easy to be a great teacher or even a good teacher.
And so there are plenty of folks out there.
And I actually love the idea of empowering folks to go and teach themselves to program
because that's kind of what I did when I was growing up.
And it was a very large part of my childhood, I guess.
But for those folks, it's really hard. And so the book has literally like screenshots, like, this is how
you set up your first project. And, and like, on Windows, on Mac, on Linux, and walks very, very
carefully step, step by step. And, and to your point, yeah, I think it's really important
for people who are learning to program to not just read.
You have to write code.
You have to take the example code, break it,
figure out what's wrong with it, fix it, tweak it.
Really getting the hands dirty is really important.
Now, I'm kind of curious now
for maybe just a little bit of nostalgia here.
You said you got started in like 97,
98 in middle school.
Okay.
What compiler did you use when you were learning C or C++ then?
Uh,
TC light.
TC light.
I don't think I'm familiar with that one.
It was a Borland,
uh,
compiler. It was a turbo compiler.. Oh, it was a Turbo compiler.
Okay.
Yeah.
Turbo C++.
Okay.
Yeah.
Okay.
It was pretty good for what it provided.
Yeah.
Yeah, definitely.
So are there any new features that you're looking forward to in C++ 17
or any modern C++ features
that you think are particularly good
for new programmers starting out?
That's a good question.
Disclaimer here, I haven't been following
the standards process super closely recently.
But as I mentioned earlier,
I think some of what I've seen
from the idea of concepts and concepts light.
It seems like it has promise for helping with new programmers
and sort of simplifying concepts, simplifying error messages, things like that.
I haven't dug deeply enough to really have a strong opinion on this.
I do remember Bjarne giving a great CPPCon talk where
it was
the impression that I came away
with, and unfortunately I can't give you a great example
off the top of my head, was like, wow, I see exactly
why this will make things easier
for people, not just who are expert
programmers, but who are new programmers.
And that got me pretty excited, but
I haven't dug deep enough
to have a really strong opinion.
Okay.
Okay.
Jason, do you have any other questions?
I think that covers it for me.
Okay.
Well, Alex, it was great having you on the show today.
Where can people find you on Twitter or online?
Sure.
So my Twitter handle is AlexAlain, or or whatever so that's a great place to find me
and uh i'm always happy to answer questions via email which is webmaster at cprogramming.com
okay yeah obviously uh people can find you at cprogramming.com and we'll put a link to uh to
the book as well on the show notes awesome Awesome. Yeah, thanks so much for having me.
This was fun.
Sure, thanks for joining us.
Yeah, thanks for joining us today.
Thanks so much for listening in
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 about that too.
You can email all your thoughts
to feedback at cppcast.com.
I'd also appreciate
if you like CppCast on Facebook and follow CppCast on Twitter. You can also follow me at
Rob W. Irving and Jason at Leftkiss on Twitter. 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.