When to Teach C++?

Some friends and I were recently debating when CS undergrads should be taught C++. People have various opinions, but it’s clear that C++ no longer enjoys the somewhat dominant position that it did a number of years ago. My own opinions are rooted in an experience I had around 1995 as a TA for a course that taught C++ to first-year CS students. I didn’t think it worked very well.

We don’t need to teach students every industrially relevant language because any competent computer scientist can rapidly pick up a new language. Rather, a language that is used for coursework should have some pedagogical value. For example, Java and C# are reasonable languages for teaching OO design. Using C is a good way to teach systems-level concepts. Using Scheme / Perl / Python / etc. is a good way to teach algorithms, program design, and the scripting style of development.

Does C++ have pedagogical value? Certainly it can be used to teach OO and systems, but should it be? My general opinion is that it should not be — the overhead is too high. First, the language is just very large. This can be somewhat finessed by teaching a subset, but even so there are difficult feature interactions that can trip up students. Second, the near complete lack of language-level runtime error checking makes C++ a pedagogical disaster (of course the same is true for C, but the language is far more manageable). Finally, in my experience the quality of compile-time diagnostics is not that great. A programmer I know has about a 10-page printout on his cubicle wall that contains a single compiler error message from a heavily-templated program. Presumably modern implementations like Clang++ are better, but still — ugh.

Anyway, my answer to the original question is that C++ should be taught late, for example in a junior or senior level projects course, after the students have learned a bit about disciplined programming and about the design of programming languages. Furthermore, it should be optional. I’d be interested to hear others’ thoughts.

15 Replies to “When to Teach C++?”

  1. In Poland, at Warsaw University of Technology, the first is C (1st semester of a 5-year-long education programme), and the 2nd is C++ (2nd semester). Then comes assembler, then Java. Structural programming is explained during the C course, OO – C++. I remember that many of my friends, including me, had difficulties when trying to understand all of the new concepts. Having no experience as a lecturer, I won’t put myself in a position of a judge – however, it sounds quite reasonable.

  2. Interesting approach! I’m a programming professor at Unifei. A nice thing we have done here is that we standardize the first programming course in the electronic and computer engineering courses to be a semester long teaching the basic concepts using C. After this the electronic students will go all way down to assembly and hardware issues and computer students will go up to OO and operational systems.
    Another point to consider is why you are teaching the language. It should not be taught per se, but is should be a tool for teaching a concept or technique. In this case I found C++ to be optimal for O.S. with the right amount of abstraction (OO) and all hardware access freedom that is needed in this case.

  3. Sounds about right: I’d wait for a specific course where a very popular toolkit written in C++ is useful (hacking on WebKit?). The usability hit is just too high for a casual survey.

  4. Maybe Clang++ gives better compiler error messages, but I am not optimistic. The principal motivation for adding “concepts” to the C++ standard was to reduce the size of the nasty template compile error messages. That they failed to add this to the standard only increases my overall pessimistic attitude towards the language.

  5. I completely agree, C++ is not appropriate for students. In our university we start with functional programming (for some months), and then learn imperative programming with Ada. This language has important pedagogical advantages, and also is required by the Software industry.

  6. C++ was the first language I was taught in high school, and the teachers successfully explained the basics — classes, inheritance, pointers, templates, etc. My experience shows that it can be done, but your concern about feature interactions is well placed. Just because it *can* be done does not imply that it *should* be.

    In my professional life, I write almost exclusively in C++. I’ve mentored several college interns over the past few years, and experience shows that becoming fluent in C++ is usually their first barrier to becoming on productive and independent. Indeed, they waste a good deal of time fighting crytic compiler and (especially) linker errors. There are gentler languages that can teach most (but not all) of the concepts that you would get from a course taught in C++.

  7. In recent years Bjarne Stroustrup has championed a different view, namely, that C++ should indeed be tought (in an appropriate manner) to 1st-year CS students. Section 6 of his paper “Programming in an undergraduate CS curriculum”,
    http://www.research.att.com/~bs/software.pdf
    argues this case, and I won’t try to summarize his arguments here.

    John, you’re undoubtably familiar with Bjarne’s arguments; I’d be interested in reading your response(s).

  8. Jonathan, I hadn’t read that Stroustrup article — thanks for the pointer.

    I generally like Stroustrup”s writing and thinking, and particularly enjoyed The Design and Evolution of C++.

  9. John – I’ve just eliminated C++ from my junior/senior level distributed systems course in favor of (please don’t kill me just yet) … Go. The end result of this is that perhaps 20+% of our graduating students won’t have ever had a course in C++.

    I don’t think it matters a bit. They’ve had C, they’ve had some Java, they’ve had some ML, they’ve had some assembly. In prior versions of the course, I didn’t actually teach C++, I just required it and assumed the students would figure it out. They did. They can do the same in the real world.

  10. A solid foundation is more important than specific language skills. “Algorithms + Data Structures = Programs” is still very much the core concept. Instead of Pascal introducing Python (both FP and OOP and effectively being executable pseudo-code). Then rounding out with Scheme (SICP ?) for FP and Smalltalk (Pharo is good) for OOP. In this day and age I would next go with ECMAScript (aka JavaScript (TM) Oracle) which is rather like Self. The big win with JS is that the rich environment of the browser, with Canvas, WebGL and SVG being available without needing to install and configure additional libraries.

    I agree with Dave, Go is latest in the evolutionary chain of C -> C++ -> Java -> C#. Once someone understands Go, they can pick up its predecessors and hopefully avoid the tar-pits as a result of their well established foundation knowledge.

    I don’t have experience with Erlang, Haskell, ML, F# so I’ll refrain from weaving them into the narrative.

  11. I’m a professional C++ programmer and I don’t believe it should be taught to beginners. You end up with too many idiots complaining about how arcane it is, how slow it is to develop in, its “unsafety”, and so on (mostly untrue with modern C++ and modern methods).

    Sometimes I get into a “my-language-is-better-than-your-language” discussions with colleagues, and I laugh at their comparison of C++ with languages like COBOL. It’s pretty clear that C++ will be around for a lot longer than C#, Java and the like, for good reasons. Also it feels like my IQ loses a few points every time I use Java or C#.

    Let a student or cadet programmer have the aptitude and enthusiasm first before unleashing the world’s best language on him 🙂

  12. I think it would be interesting to see how many concepts could be covered with just Haskell. It is obviously considered a functional language, but ghc has extensive libraries with support for low-level programming, concurrency, and distributed concepts like transactional memory. Moreover, the foreign function interface makes it easy to interoperate with C and/or assembly if the need arises.

  13. I think a person needs to examine the motivation behind teaching (or learning) C++. In use, it’s okay, but learning it was a bear (and that was before templates).

    So if you want to introduce concepts, take a look at other languages first, unless everyone already knows C++.

    If you need to teach C++ to prepare students for industry, teach a class specifically about C++, and how best to use it (and why).

    So I guess I’m saying that C++ should be taught late, if at all.

Comments are closed.