views:

386

answers:

2

I have been teaching some bright high school kids Python for 3 months now (for most of them this was their first experience with programming). I've decided to take the best of the group of give them a quick (120 minute) introduction to C++. They're hard-working enough to take what we give them and learn things further on their own.

Are there any good slides and other resources (cheat sheets and online books/tutorials) that I could use? I'd prefer to reuse existing material if it's available, but most of what I can find goes the other direction (C++ to Python)!

Addition information from my comments below:

Reason for choosing C++: While Python was a good choice for introducing them to programming, most programming competitions (for which we're training them for!) don't allow Python. The major one only allows C++ and Pascal, and I have 0 Pascal experience. These are some truly bright kids. They're hungry for knowledge and as a result we give them a taste of various things and they go out and explore the things that interest them on their own, i.e. they make up their own minds. It works well.

I'm doing this on Ubuntu, so I'll use Kate as the IDE. I plan on mentioning makefiles and they can learn it on their own if they wish.

I plan on covering the difference between Python and C++ wrt:

  • typing
  • io (including files)
  • if/else/for/while
  • functions
  • basic stl use (at least vector, string, algorithm and then touch on some others)
  • basics of classes
+4  A: 

There's a good reason why people go from C++ to Python and do not go from Python to C++. I'm not sure I see the point in confusing them with all the quirks and weirdness of C++, and I think the reason why you can't find much material is because others agree. Python is good, C++ is something we only do when a client forces us to.


Background

For a while I taught C to COBOL programmers. Many complain about C-isms. And correctly, BTW. From a COBOL starting point, C is very hard to learn because it lacks COBOL features. They didn't like it.

Also, I used to teach SQL. Everyone compares SQL with flat-files or other non-SQL database access. In the olden days, COBOL folks would have used DL/1 with a database called IMS. By comparison the relational model and SQL were awful. Truly horrible. Note that IMS is barely used anywhere and SQL is still popular. That's not the point.

Learning a new language (C, SQL, C++) is not an informed decision -- you don't know the new language -- your opinion is uninformed. You must fall back on a subjective value judgement: the old language/technology is more familiar and therefore "better". That's human nature, and you're going to have to find a way to work past people's urge to cling to what they know when confronted with the unknown.

Compounding the natural tendency to complain about the new/unknown, you have the further problem that C++ really is bad. You have two hurdles to jump. Comparing with Python assures that you will trip over one or both.


Edit

(First, update your question with additional information...)

On C++...

You should probably begin with C++ as a whole new language, not as an "evolution" from Python. The transferrable skills (abstraction, sequential reasoning, etc.) are independent of all languages.

You should, further, teach C++ as if Python didn't exist, and allow your students to draw their own conclusions about C++'s similarities and differences from Python.

I would not, for example, try to compare SQL and Python; nor would I try and compare HTML and Python. In a similar way, I would stay away from any parallels between C++ and Python.

The issue is that C++ has so many foreign constructs that there's no bridging from Python.

Starting on day 1, C++ has the cout << construct which is NOT an analog of print. It's an operation between disparate types, and has some support for primitive types. There's nothing like this in Python and it's the first thing you'll cover.

Then, C++ has "primitive" types which are not objects and do not have methods. This is the second thing you'll cover and covering it in the negative (what these "objects" lack) is probably just confusing. Better to ignore Python and cover primitive types like they're an ordinary thing, not an accident waiting to happen.

Variable declarations are -- of course -- a show-stopper. I'd ask "why can't C++ reason this out?" What's your answer? "It doesn't, get over it." Every will want a generic object & declaration, but that's crazy. At this point, you have to separate an object from it's type, since the C++ type is carried in the variable declaration and the object is just a puddle of bits. Again, the "negative" sense of "C++ separates these things" probably won't be helpful. You'll need to focus on some positive reasons -- and avoid comparison with Python.

C++ has references and pointers. If there's any way to avoid teaching them about pointers, your life will probably be better. References are closer to what they're used to than pointers.

Input (via << cin for example) is nothing like Python because a variable gets updated; an object isn't created (necessarily).

Statement syntax is easy. They already know how to format an indent. A few extra {}'s won't be a terribly big problem. I used to teach C to COBOL programmers, and they couldn't get the {}'s right, either.

Function definitions will probably be easy. The mandatory return business in C++ (there's no default return None behavior) should (again) not be a negative, but a positive. It's more explicit or some such justification.

Objects will be a chore. Find a collection library you can live with (like STL or something) and teach that in depth. Python has glorious collections, C++ has nothing. Avoid teaching about primitive arrays if you can -- they're an accident waiting to happen.

This collection library should be (a) complete and (b) emphasize references over pointers. It would probably be helpful to use a library which derives from object, since that's somewhat more Pythonic. However, this may only raise the frustration level.

Class definitions come last, and will be a Herculean task. The endless overheads of separate class declarations in .hpp files, plus the confusing issue of when to use a reference and when not to use a reference will be a pretty big deal. I think that "always use a reference for objects" and "never use a reference for primitive types" is probably the simplest (and cleanest) way to come to grips with C++.

Bottom line. Cover C++ in isolation. Let them draw their own conclusions. The differences are too huge to construct a bridge from Python to C++.

S.Lott
I have other reasons for teaching them C++. While Python was a good choice for introducing them to programming, most programming competitions (for which we're training them for!) don't allow Python. The major one only allows C++ and Pascal, and I have 0 Pascal experience.
marcog
Nevertheless, I think giving someone 90 minutes of teaching in C++ is going to do more harm than good. You learn just enough to be able to create new and exciting forms of undefined behavior, and then spend the rest of the week debugging it. If you're training them for programming competitions that only allow C++, then you should focus on C++ primarily, perhaps after a short intro to programming in Python. How much do you realistically hope to achieve?
jalf
That would be true if these were average people, but these are some truly bright kids. They're hungry for knowledge and as a result we give them a taste of various things and they go out and explore the things that interest them on their own, i.e. they make up their own minds. It works well, so I do hope to achieve a lot.
marcog
Thanks, that's excellent! I've updated the question as you suggested. I disagree that a comparison to Python should be ignored. The important message I want to get across is how they differ to give them a better opportunity to make an informed decision about which language they prefer.
marcog
Here's what a comparison with Python gets you "C++ sucks". End of learning. The only way to avoid this is to avoid the comparison. As it is, they will draw their own conclusion, namely, C++ sucks when compared with Python. You need to get as far as you can before they reject C++. They will reject it because, by comparison, it sucks.
S.Lott
"C++ sucks [when performance isn't a factor]". The algorithms we teach are highly computational and therefore Python is so much slower (100x on average). The STL is also far more powerful for these algorithms. Anyway, why hide the bad side of C++? If they have reason to dislike it, I'd rather give them those reasons early on and try explain why C++ does it the way it does. Let them reject it if they want to.
marcog
They don't know enough to get past the "new languages suck when compared with my old language." That's the primary reason people will dislike it, and it's a universal response to all new things. To get past this, you have to start fresh and avoid comparisons.
S.Lott
I don't think it matters how bright they are. You need to know C++ to use it. If you don't know C++, then no matter how bright you are, you're going to screw up. And 90 minutes is nowhere near enough to get to know c++. I don't agree with S.Lott that they're necessarily going to hate C++. They just won't have a chance of learning it well enough to use it.
jalf
"They just won't have a chance of learning it well enough to use it." After 4 x 30 minute classes on Python, they were submitting solutions to non-trivial problems showing a decent understanding of the language. I don't mean to sound arrogant (I am still looking for help after all :P), but it does matter how bright they are.
marcog
@jalf: "Hate" is too strong a word. But all new things have an implicit barrier -- "new" == "different" == "hard" == "what I previously did was better/easier". Getting over that barrier is what's important, and an explicit connection with Python doesn't seem helpful.
S.Lott
@S.Lott Your point about wanting to stick to what they know is actually very interesting. I'll have to think of a way to work passed that. Some kids (about 1/4) in the class with them already know C++ and those kids we're going to teach Python simultaneously. Since it's a very interactive environment I'm hoping they will exchange thoughts on the language they know. Perhaps this will break the barrier of sticking to what they already know.
marcog
marcog
+6  A: 

Bruce Eckel's Thinking in C++ is a reasonable free online book. Obviously an entire book's worth of material is too much to fit within a single 90 minute session, so you'd have to do a lot of work yourself to select a sensible subset to present. Flow control, functions, plus std::vector, std::string and streams can get you a surprisingly long way.

Another extremely valuable online resource is the C++ FAQ.

A quick google search turned up this C++ for Python Programmers page, which helpfully highlights the chief differences between the two languages (static v. dynamic, values v. references, compiled v. interpreted, syntax etc.).

I guess a free IDE would also be useful. It might be a lot to ask them to learn the intricacies of GNU Make. That's a couple of hours on its own.

Alternatively there is a free edition of Microsoft Visual Studio. :)

Richard Wolf
-1 for suggesting a buggy, low-quality IDE that hasn't been maintained for half a decade. Remove Dev-C++, and the rest of your post warrants a +1.
jalf
Pity Thinking in C++ doesn't come with slides (it's what I really want out of this question), otherwise it's usually the book I recommend too.I'm doing this on Ubuntu, so I'll use Kate. I will just mention make and they can learn it on their own if they wish.I might up the time to 120 mins. I plan on covering the difference between Python and C++ wrt typing, io (including files), if/else/for/while, functions, basic stl use (at least vector, string, algorithm and then touch on some others), basics of classes.
marcog
"-1 for suggesting a buggy, low-quality IDE": Ooo, way harsh. I had fond memories of it, but I suppose you're right. Deleted.
Richard Wolf
Cool, changed to +1 then. The rest of your post is good. :)
jalf