CppCon 2015: Kate Gregory “Stop Teaching C'

preview_player
Показать описание


To this day most people who set out to help others learn C++ start with "introduction to C" material. I think this actively contributes to bad C++ code in the world. For the past few years I've been teaching C++ (and making suggestions to folks who intend to teach themselves) in an entirely different way. No char* strings, no strlen, strcmp, strcpy, no printf, and no [] arrays. Pointers introduced very late. References before pointers, and polymorphism with references rather than with pointers. Smart pointers as the default pointer with raw pointers (whether from new or &) reserved for times they're needed. Drawing on the Standard Library sooner rather than later, and writing modern C++ from lesson 1.

In this session I want to talk about the specific advantages of teaching C++ this way – a way that’s very different from the way you almost certainly learned the language. You’ll be pleasantly surprised to see what you get to leave for later or never cover at all, what bad habits you don't later need to correct, what complicated concepts actually become accessible to beginners, and how you spend a lot less time dictating magic spells you can't explain yet, and more showing someone a comprehensive, sensible, and understandable language.

You don't have to be a trainer to come to this session. If you ever mentor other developers and show them your C++ code, if you ever help somebody choose a book or a course or other material to learn from, or even if you occasionally feel bad that you work in a language that's hard to learn, come and see how one philosophical shift can turn that very same language into one that's actually pretty easy to learn!



*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

Less than 24 hours and already people in the comments are missing the point and being stupid. Is it so difficult to understand that Kate is simply saying to not teach C >> when teaching C++ <<? They are separate languages, that require extremely different programming mindsets.

C is and will always be important/relevant.
Do teach C. Do not teach C when teaching C++.

vittorioromeo
Автор

The title is ruining the beauty of this video. It should be Stop using C-Style to start C++ course. She has excellent points.

EngBandar
Автор

Just found out this gem today.

I'm not a C or C++ Dev, but it really makes me wonder if I ever made things go a little harder or more complex, like when she points out that objects and classes are buried in the 17th chapter.

DieDona
Автор

This comment section is full of defensive C programmers, who completely missed the point of the video. This *isn't* an attack on C.

Spiderboydk
Автор

This is a fantastic presentation. It should be broadcast far and wide. When teaching C++ don't teach C, that is a different language for a different purpose.

garethbuxton
Автор

I missed this talk when I was at CppCon '15 and really regretted it. I'm so glad I watched this video. Fantastic material really well presented!

PabloHalpern
Автор

Came to realise that I was taught C with classes in high school. Took a while to unlearn so many of those practices.

dennis_johnson
Автор

I'm glad this turned out to be "Teach C++ if you're going to teach C++" instead of "It's time to let C die." How click-baity of a title though....

Syke
Автор

Each and every talk given by Kate Gregory I've seen so far is just amazing and great! Thank you!

coderk
Автор

I've been programming in C++ for ~10 years and sometimes I still add * and & in suspicious places to get the compiler to stop complaining

seancpp
Автор

Good talk, this is absolutely how C++ should be taught and (as far as I know) is not. I was one of the people that was taught C++ more as C. Having now learned C++ somewhat properly, I have come to the same conclusions as Kate. References should be introduced before pointers, who cares about arrays *as a starting point* (should use vectors), standard library is just that -- a library of standard things you can use so teach people like that. All the other stuff should go later (new/delete, unique ptrs, etc.) as the advanced under the hood stuff you care about when you get to it.

My analog (as a physicist by training), to the way I was taught C++, is like starting a course on classical mechanics by teaching about a rod rolling down a ramp by starting with inertia, moving to friction, and then being like by the way there's some kinematic equations that describe a lot of movements that you haven't learned yet. Why the hell are programmers teaching "ramp physics" for a mechanics course when they should be starting with kinematics?

andrewholmgren
Автор

This almost makes me want to give C++ another try. I know for a fact I was taught C++ terribly, I tried learning on 3 separate occasions. Finally got it enough to make stuff work when there was a grade tied to it, but it started as a lot of voodoo, a lot of comparisons to Java that just didn't work, and a lot of "Why is this so much easier in every other language?" I had to learn RUST to really understand C++, and now I almost want to give it another go. Almost.

knife_wizard
Автор

Great talk as usual Kate, but can't help but feel like you're preaching to the choir here. Recently I sat in on an "Advanced Programming" postgrad course that taught C++ from scratch for people who weren't familiar with C yet. RAII was never even mentioned and smart pointers were introduced on the second last day! (after two weeks of using new and delete and allocating almost all arrays on the heap - that's right, no mention of std::array either...)
During that lecture, some of the comments from students on the chat were things like:
"I really don't like smart pointers"
"Could we do a few use cases of where it would actually make sense to use a smart pointer? I don't see why they're useful"
"So are unique pointers just pointers for lazy people?"
Gee, what a great intro to C they got.

rpmcmurphy
Автор

Teaching C first is roughly like teaching Python by starting with how Python bytecode works. There are details down in the guts that will make you a better programmer if you understand them... But unless you're teaching people who want to delve into the nitty-gritty and gain a language-independent understanding of how computers function rather than people who just want to make the lights blink there's no reason to start there.

laurenceperkins
Автор

I know C++ for about 4-5 years at this point but I attend the C++ course at university nonetheless. I was curious how it would be tought (and to get a good grade easily :D).
I'm suprised how well the teacher is teaching it. We don't bother talking about C. We have a lecture a week and directly dived into C++.
1) Basics and <iostream> + <iomanip>
2) Classes
3) exeptions and std::string
We did algorithms, containers, simple templates (and auto) and also some basic SFML.

We will maybe look at C at the end if we have a week or two left.

sera_kath
Автор

I completely agree with her, as a high school student who also develops software/web apps, I find it painful how c++ is taught in school. Its c++98 with all the bad parts. The problem is we teach c style c++ rather than c++ itself. Although I had learnt c++14 before, learning c++98 is useless in the modern era

KaranLobana
Автор

Great talk. You barely need pointers, manual iteration and built-in arrays/char arrays anyway if you write C++ according to current standard of what is good. It actually makes a lot of sense to teach that stuff as advanced stuff later in the course, rather than, for example, begin by teaching for(int i=0; i < n; ++i) and THEN present a range-based for loop and std algorithms as an advanced topic, when it should be the other way around.

AlexanderRevo
Автор

Totally agree! Now, let me get back to figuring out what caused that 200-page error message. /s

unclelindsey
Автор

A great talk. I was self-taught in the early 90s, from a book. I feel fortunate that the author put a great emphasis on the value of RAII for non-memory resources such as Win32 window handles. It is arguably the most important idiom in the language, and could easily be presented on Day 1 or 2 or a course.

UnicycleBloke
Автор

True :) First time I wrote my C++ program in industry, my managers reply was you are writing C in c++

vikramful