tags:

views:

929

answers:

7

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?

Which topics do you consider most crucial?
Which topics should be added or removed?
Which topics just can't be covered adequately in a short time?

+6  A: 

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
+17  A: 

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
+2  A: 

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
+2  A: 

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
+3  A: 

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?
eed3si9n
Konrad Rudolph
+4  A: 

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
A: 

As Rob Rolnick said, you should take some time on memory management, and especially RAII.

Alexandre Hamez