Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a young lecturer friend who is going to teach the undergraduate C++ course in CS. He asked me for some suggestions regarding how the course should be organized. Now I am asking you. I have seen many trends in universities which leads to a nasty experience of C++. So, please suggest from a professional programmer's point of view.

For your information, the students going to take the course, have taken course like "Introduction to programming with C" in previous semester.

share|improve this question

closed as off-topic by gnat, GlenH7, MichaelT, Kilian Foth, World Engineer Oct 22 '13 at 1:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking career or education advice are off topic on Programmers. They are only meaningful to the asker and do not generate lasting value for the broader programming community. Furthermore, in most cases, any answer is going to be a subjective opinion that may not take into account all the nuances of a (your) particular circumstance." – gnat, Kilian Foth, World Engineer
If this question can be reworded to fit the rules in the help center, please edit the question.

13 Answers 13

up vote 14 down vote accepted

Bjarne Stroustrup wrote a book recently that's devoted to teaching C++. It emphasizes STL's algorithms and data-structures.


share|improve this answer
This is exactly how C++ (not C, not C with classes, but C++) should be taught. –  FredOverflow Dec 24 '10 at 13:03

There should not be a "C++" course in a computer science curriculum. If a specific language is used for a specific class, that should just be incidental to the class.

Does anyone think MIT, Carnegie Mellon, or other top-tier schools teach "C++" and "Java" classes? They teach an "introduction to programming" class that focuses on learning to program while mastering the mechanics of a single language, and everything beyond that is about computer science and uses whatever language the professor, dean or department feels is appropriate.

When I was at Carnegie Mellon, the Intro Programming course was in C, Fundamental Structures of Computer Science I was in C++ the following semester, and Fundamental Structures of Computer Science II was in Standard ML the semester after that. (These were the three basic CS courses everything else built on.) The first course spent pretty much the entire time on the C language, but the subsequent two courses spent maybe a week on the languages they used, and that only because they were still low-level classes. Subsequent classes spend less time on languages and mechanics, and all of their time on actual computer science. CS students are expected after their first couple languages to just pick up additional ones.

One also shouldn't say "But that's for MIT/CMU/Stanford/Caltech/whatever students, what about everyone else?" I wouldn't short-change students' educations just because they didn't (or couldn't) attend a top-tier university. If one has the opportunity to help provide a great education, it can be argued one has the moral/ethcial duty to do so.

If your friend is adjunct faculty and is required to teach a "C++" class, I'd strongly suggest taking a look at what some of the top-tier schools teach in their other courses, and building the course around that. For example, the school may not teach much about data structures right now; the class could be turned into "Data Structures Using C++." The lessons can be structured to add C++ language concepts as needed to implement the fundamental data structures, which will give students a solid grasp of both those data structures and the language itself.

It will probably help the students enormously in their education as well to come out of a second-semester course with a solid understanding of fundamental data structures.

share|improve this answer
The actual name of the course is "Object Oriented Programming". But everybody calls it "C++" as this is the subject taught in reality. –  Gulshan Dec 30 '10 at 8:08
There is a separate course on data structures –  Gulshan Dec 30 '10 at 8:09
Will the students have taken the data structures course already, or is it in their future? –  Chris Hanson Dec 30 '10 at 8:12
Probably they have already taken. But I am not sure. –  Gulshan Dec 30 '10 at 9:56

Start with high level concepts, so the students can make correct, interesting programs in a reasonable amount of time. For example, introduce vectors, iterators and algorithms early on, and defer discussing arrays and pointers until very late in the course. This is exactly the approach taken by Bjarne Stroustrup, the inventor of C++.

What you absolutely should not do is start with plain C, then go to "C with classes", and cover the STL in the last lecture. Many books have taken that approach which gives a warped impression of what C++ is.

share|improve this answer
if you read the question, students have taken "Introduction to C" which means they already know pointers/arrays. –  segfault Dec 24 '10 at 13:10
@Bo Tian: As somebody who has taught C at the college level, not everybody comes out of those classes proficient with pointers, although I can't imagine getting an A or B without some skill with them. –  David Thornley Dec 28 '10 at 20:40

I like Xavier's anwser. Accelerated C++ is another good approach on the subject.

In all cases, don't assume the standard library is an advanced topic, or anything that doesn't deserve more than being in the appendices. No. The standard library is as important as the core langage itself. You won't have correctly taught the language if you have ignored these parts, or the RAII.

Unfortunatelly your students will have already seen the C before: they may think the C++ is just a continuation of the C and thus miss important differences.

share|improve this answer

I recently took a 8 lecture course on C/C++, the syllabus is:

Introduction to the C language. Background and goals of C. Types and variables. Expressions and statements. Functions. Multiple compilation units. [1 lecture]

Further C concepts. Preprocessor. Pointers and pointer arithmetic. Data structures. Dynamic memory management. Examples. [2 lectures]

Introduction to C++. Goals of C++. Differences between C and C++. References versus pointers. Overloading functions. [1 lecture]

Objects in C++. Classes and structs. Operator overloading. Virtual functions. Multiple inheritance. Virtual base classes. Examples. [2 lectures]

Further C++ concepts. Exceptions. Templates and meta-programming. Java Native Interface (JNI). Examples. [2 lectures]


EDIT: Since the students already took a lesson in C, it would be nice to not repeat the same things (basics, pointers etc.) and teach features of C++ like class, STL, templates.

share|improve this answer
Introducing pointers to novice programmers in lecture 2 or 3 is a terrible idea. A course on "C/C++" is also a terrible idea, they are two distinct languages with very different goals and idioms. –  FredOverflow Dec 24 '10 at 13:00
I don't think so. Item 1 of "Effective C++" says that programmers should view C++ as a federation of languages - C, Object-oriented C++, Template C++, STL (page 12). It's perfectly reasonable to start with C part of C++ and progress to other "languages" of C++. –  segfault Dec 24 '10 at 13:09
@Bo: “it’s perfectly reasonable …” – Well, Bjarne Stroustrup argues differently, and I agree. Pointers are advanced stuff in C++ and just confusing (and unnecessary) to beginners. –  Konrad Rudolph Dec 26 '10 at 17:59

I do not agree that iterators and the STL should be beelined for in an academically-minded C++ course. I'd far rather have students focus on the ability to build and compare different collection classes of their own, and understand the tradeoffs of whatever class they might encounter.

Aim for producing graduates who have enough grounding to look at the function prototypes in the STL docs and go "oh this is one of those types of approaches". Then they can have an equal confidence if they dig into some the big name codebases that they heard of which "use C++" but which don't use STL... like how Firefox foregoes std::string and defines its own (nsAString_Internal) hierarchy. Or nearly every Qt program out there, etc.

In the real world, cross-cutting concerns often preclude projects from using the STL. That can be issues like threading on embedded systems, implicit sharing, or Unicode. It's precisely the power of C++ to attack these problems with custom solutions that has kept the language relevant when going up against its nimbler interpreted competition. People who live and breathe C++, even for purposes best suited for shell scripting, miss that point.


Since most of the other languages people are exposed to these days are interpreted, a real understanding of "compile-time" vs "run-time" is essential. Not just in terms of performance but in terms of globally assuring certain types of errors don't exist. Template syntax can get ugly, but all the more reason to show why anyone bothers with it.

Throw Valgrind in there and get them used to understanding what's happening to their memory from day one, and how automatic memory management can help. Let them write their own auto_ptr and then give them situations where it will flop in a simple collection. Have them write essays about why and re-derive unique_ptr and shared_ptr.

Bjarne Stroustrup makes some great points in his C++ teaching (which I often link to). But he's usually making arguments to hardened C programmers that if they think their C programs are faster than comparable STL-based C++, then the programs are probably only faster because they are incorrect. This takes the foregone conclusion that your problem required C-level performance in the first place, and no programmer of this generation should be assuming that.

In summary: I'm not suggesting "C with classes". I'm suggesting "Grasping the design tradeoffs in C++ software design [leveraging tools like inheritance, RAII, templates and overloading]" Too much STL emphasis up-front will just lead to a bunch of angry Java-converts-in-training who can't cut their teeth on showcase C++ projects.

share|improve this answer

Pointers and Objects. Can't go wrong with that. Also make sure they get plenty of lab practice.

share|improve this answer
Starting with pointers is a terrible idea, because the pointer mechanism is used for so many different concepts that a novice programmer cannot possibly understand from the early beginning (dynamic allocation, sharing, dynamic dispatch, simulating call by reference, recursive data structures...). –  FredOverflow Dec 24 '10 at 13:03
They aren't exactly novice, considering they've already done a course on C. If not now, when else will they learn it? –  Pulkit Sinha Dec 24 '10 at 15:35
“when else …?” When they need it, and in C++ that’s pretty late. See my comment below Manoj’s answer for details. Don’t teach C++ like it’s some extension to C – it’s not. It is used essentially completely differently. In fact, their C knowledge doesn’t help them very much at the beginning of learning C++. –  Konrad Rudolph Dec 26 '10 at 17:57
I was somewhat surprised to see pointers (and the discussion on memory management) so late in Stroustrup's book. I've relearned C++ probably 6 times in the last 20 years (I do developer docs) and also highly recommend the text. –  SnoopDougieDoug Dec 27 '10 at 4:22

I would agree with what a couple of the other responders have suggested; Accelerated C++ is an excellent starter book on c++. It is really well paced, and covers the majority of topics required for under-grad study. The book's contents would give you a good structure and the basis of a syllabus, augmented by more detailed books if necessary.

share|improve this answer

Working on long-term projects with other developers

Most bachelor-level programming courses seem to touch on the basics (objects, pointers, comments are good, etc) at some point - some more effectively than others.

I rarely hear about courses that focus on making you read and maintain someone else's code for 3-12 months (probably because the university class structure does not easily facilitate this).

The developers that I know all seem to have picked this up after they were hired - after reading/writing enough shitty code, you get a better feeling about how to write code that won't be a thorn in your side when you have to maintain it later.

Even a bad class with enough homework assignments can teach you what you need to know about syntax, assuming you know how to read the docs. But the ability to work on an actual project is something that I only see getting picked up after graduation.

share|improve this answer
How much you agree with this answer may very well depend on your definition of "basic". If you consider basic to mean first-year, this might not seem appropriate. I wrote this answer imagining "core classes to a 4-year programming education". –  TehShrike Dec 28 '10 at 23:54
That'd be an interesting approach - give next year's class the job of cleaning up and extending the code from last year's class! –  GrandmasterB Dec 29 '10 at 4:57
Hah, that's not a bad idea! But I was mostly thinking of having to look at your own code 6 months later, and talk to the person whose code you had to fix. –  TehShrike Dec 29 '10 at 5:02

One thing that I keep wishing would get taught in language-specific courses at any level of education is "when is this language not suitable for a task?" Too many people wander around the programming world convinced that Language/Technology X is the One True Hammer to hammer all problems with and the result is ... well it's what you see in software around you. It would be nice to have courses say both what languages are good for and to also point out the things they're perhaps less than ideal for.

share|improve this answer

first thing first ,start with concept of OOPs using real life examples and then start c++ by comparing with other languages that student knows.

share|improve this answer

This should really be a course in OOP and\or data structures.

If they have had an introduction to programming using C already, then there's not a real need to go in depth into basics of the language like pointers and arrays. Make them start with an object orientated C programming style and force them to do some inheritance style programming, the need for C++ should click automatically after that painful experience and set the tone for the rest of the class. A good starting assignment could force them to write code to convert between 3 to 5 different currencies.

share|improve this answer

The first and foremost, start with the pointers. Yes, I understand that this will be covered in C class, but unless pointer concept is clear the students are not going to understand the later topics. Approximately this is how I will go about it.
1) Pointers
2) Reference
3) Code reuse
4) Objects
5) Classes
. . .

share|improve this answer
Code reuse should be relegated to a different course. It's a higher level concept that most people at this level will not really appreciate and will see it as a waste of their time. Unless the course is structured in such a way as to make it obvious what parts of previous assignments should be reused. –  davidk01 Dec 24 '10 at 8:08
That's right. Code reuse is part of the software Engineer. But the thing is without explaining this, the students do not understand the difference between C and C++. And they think C++ is higher of C and continue on that line. Hence I feel it is important first to explain why C++. –  Manoj R Dec 24 '10 at 10:23
Starting with pointers is a terrible idea, because the pointer mechanism is used for so many different concepts that a novice programmer cannot possibly understand from the early beginning (dynamic allocation, sharing, dynamic dispatch, simulating call by reference, recursive data structures...). –  FredOverflow Dec 24 '10 at 13:02
I agree with @Fred. Starting with the nitty gritty is always a terrible idea. First teach high-level concepts so that the students can start programming. Only then (and as required) teach low-level concepts. So your order is almost exactly inverted. Furthermore, most of the time when programming in C++, pointers are completely irrelevant. I’m currently developing a library that doesn’t contain a single pointer declaration so far (several thousand SLOC). Of course, this assumes that you’re doing it right, using high-level constructs instead of pointers and dynamic memory. –  Konrad Rudolph Dec 26 '10 at 17:56
@Konrad Rudolph Are you using smart pointers? Or not using dynamic allocation at all? –  Gulshan Dec 27 '10 at 9:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.