12

In a few weeks, we'll be teaching a crash course on C++ for Java programmers straight out of college. They have little or no experience yet with C or C++.

Previous editions of this course were just 1 or 2 half-day sessions and covered topics including:

  • new language features, e.g.
    • header vs. implementation
    • pointers and references
    • memory management
    • operator overloading
    • templates
  • the standard libraries, e.g.
    • the C library headers
    • basic iostreams
    • basic STL
  • using libraries (headers, linking)
  • they'll be using Linux, so
    • Basic Linux console commands
    • GCC and how to interpret its error messages
    • Makefiles and Autotools
  • basic debugger commands
  • any topic they ask about

During the course, each person individually writes, compiles, runs, and debugs simple programs using the newly introduced features. Is this the best way to learn?

  1. Which topics do you consider most crucial?
  2. Which topics should be added or removed?
  3. Which topics just can't be covered adequately in a short time?
palm3D
  • 7,970
  • 6
  • 28
  • 33
  • This would be on-topic at https://cseducators.stackexchange.com/ (though since it's still in private beta, it's easiest to enter through here https://area51.stackexchange.com/proposals/92460/computer-science-educators) – Ben I. Jun 02 '17 at 17:11

7 Answers7

22

I can only once again point to Stroustrup and preach: Don't teach the C subset! It's important, but not for beginners! C++ is complex enough as it is and the standard library classes, especially the STL, is much more important and (at least superficially) easier to understand than the C subset of C++.

Same goes for pointers and heap memory allocation, incidentally. Of course they're important but only after having taught the STL containers.

Another important concept that new students have to get their head around is the concept of different compilation units, the One Definition Rule (because if you don't know it you won't be able to decypher error messages) and headers. This is actually quite a barrier and one that has to be breached early on.

Apart from the language features the most important thing to be taught is how to understand the C++ compiler and how to get help. Getting help (i.e. knowing how to search for the right information) in my experience is the single most important thing that has to be taught about C++.

I've had quite good experiences with this order of teaching in the past.

/EDIT: If you happen to know any German, take a look at http://madrat.net/coding/cpp/skript, part of a very short introduction used in one of my courses.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    `if (name == "Fred") cout << "Willkommen" << endl;` I think I like your tutorial :) – fredoverflow Jan 06 '11 at 12:28
  • @FredOverflow: I would argue that since they are coming from a Java background and are therefore already comfortable with OOP in a manner not too dissimilar to that of C++, that spending some time on the C subset and basics of pointers, dynamic memory allocation etc. is exactly what is needed. – haziz Apr 28 '12 at 16:00
  • 1
    (continued) Pointers *do* have their place. But not at the beginning of a C++ course. – Konrad Rudolph Apr 28 '12 at 16:53
  • +1 for the pointers comment. I am currently working on a project for a game-playing AI, and I believe I only have pointers in one spot of my program. I use them to indicate which player will definitely go first (with `nullptr` if both are equally likely), so even then, they aren't resource-managing pointers (my actual objects are ultimately stored in a map inside a class on the stack). However, the more I consider it, the more I realize that this is bad design, and I would solve a more general problem in the game by using some sort of vector solution to indicate multiple levels of turn order. – David Stone May 05 '12 at 14:54
  • Pointers often seem to be the best solution to something, but I've found that the actual best solution tends to be to not use indirection at all, or use references, or use something else entirely. I outline what I believe to be the "how to create objects" hierarchy in this post: http://stackoverflow.com/questions/10169283/stdqueue-initialization-with-null/10169494#10169494 – David Stone May 05 '12 at 15:00
6

If they are coming from a Java world, they are used to garbage collection. As such, I'd probably spend a bit of time talking about smart (reference counted) pointers, and how they compare to garbage collection.

Rob Rolnick
  • 8,519
  • 2
  • 28
  • 17
4

If you are going to put a lot of Java programmers straight out of college to write production code, I'd say the first thing you should be concerning is pointers and memory management.

Really, those who come directly from managed code rarely have the skills to debug pointer-related exception, let alone use it correctly, or even understands how their language/tools utilize it.

Pointers is how you think not just write code.

The framework and coding practices can be taught as tips and notes along the way.

But failing to understand pointers when writing C code is just waiting to shoot yourself in the foot, if not the head.

chakrit
  • 61,017
  • 25
  • 133
  • 162
4

I would like to add that you should make sure to point out where they can find language and API references. In java, the API and language specification is at your fingertips online at java.sun.com... with C or C++, it's not quite as simple and easy to find reference documentation.

Whenever I am doing something in C or C++, that is my biggest problem... trying to find what I need. I usually turn to cplusplus.com, which usually has what I need, otherwise I google for it. If you have a set of references you use (online or in the form of books), list them and tell them what you use each reference for.

Mike Stone
  • 44,224
  • 30
  • 113
  • 140
3

Memory management (pointers, allocation etc), basics of STL and templates (since STL uses templates). I think STL is important since one would be missing the richness of the Java SE class library in C++.

axk
  • 5,316
  • 12
  • 58
  • 96
3

I would spend a whole day discussing how to write a good class in C++. Deitel & Deitel may help as a reference.

  • When are constructors called?
  • When are assignment operators called?
  • When are destructors called?
  • What's the point for const Foo & a_foo?
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
0

You should take some time on memory management, and especially RAII.

Alexandre Hamez
  • 7,725
  • 2
  • 28
  • 39