What to teach when teaching C++ ?
These are the important topics to teach in an advanced c++ course according to me:
- Virtual calls in constructors
- Relaxation of overriding rules
- Class initialization
- Using several classes for state description (ex: sockets, list appenders with state change)
- No overload resolution on returned parameter (explain why)
- How to forbid a stack allocation (especially if "delete this" is involved)
- How to forbid heap allocation
- How to use scope for the control (action in the destructor)
- How to forbid derivation (2 methods ?)
- Discuss the various implementation mechanisms for virtual methods (especially when virtual inheritance is involved)
- New casts
- Control of ordering of events by the mean of constructors
- C incompatibilities
- Warn against overload with const
- Warn against slicing with data loss
- (Warn against ?) overload on enumerated types, on int and char
- Booch / UML notation ?
- Mix-in ?
Idioms:
- Fast memory allocation
- smart pointers
What a C++ exam should look like ?
You want to write a C++ exam ? You don't know what to ask for ? Think that
you should manipulate the following:
- classes and inheritance
- virtual method
- delete / new
- constructors and destructors (and especially passing them parameters from derived classes)
- standard conversions (especially with ref and const)
- User-defined I/O
What pitfalls should be avoided ?
Don't go into deep object-oriented analysis in a C++ course. C++
is complex enough, and so are object-oriented analysis / design
methods They should be handled in a separate course. Also many
students (and not-so-students) don't understand the contribution of
object-oriented analysis and design, and of engineering principles in
general (such as "keep things simple"), simply because they haven't
worked on sufficiently complex projects, or they haven't worked enough
in a team. Thus they think that "you're always successful if you
program right" (no need for a particular organization or systematic
approach of programming), which is basically true for most of the
programs they have developped.
I also keep thinking that young minds
enjoy a much more abstraction ability than experienced (read: older)
programmers, which make methods less essential to them. Just make them
work in a team on a very hard project, they will understand. Make this
project sexy, so they will be highly motivated: "this semester project
is a multi-users, distributed virtual reality, bloody shoot'em all
game with colorful display and heavy metal sounds" (yeahhh !!!).
What almost every trainers do (including myself), and may not be right
If you want simple classes to start, use "stateless" classes
such as data types (integer, lists, strings), which may be easily
described as abstract data types. This may seem paradoxical for
"objects" which are not "values".
If you have had a difference experience as a C++ teacher, or if you
have any comment, don't hesitate to drop me a line.
Christophe Tronche, ch@tronche.com