The Artima Developer Community
Sponsored Link

Weblogs Forum
The miseducation of C++ programmers

8 replies on 1 page. Most recent reply: Aug 28, 2005 5:24 PM by Howard Lovatt

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

The miseducation of C++ programmers (View in Weblogs)
Posted: Aug 18, 2005 6:21 AM
Reply to this message Reply
Summary
Chuck Allison stated in his latest article the unfortunate fact: "C++ novices don't learn templates, let alone CRTP, in their first week". This represents one of the big problems with how C++ is taught to novices.
Advertisement
Here is the problem: an array IS a template. It should be taught as such. Better yet, skip arrays and go right to std::vector. Novices can grok templates if given a chance. The older generation of C++ educators I find are unfortunately inclined to teach C++ like they learned it. i.e. C first. My students (if anyone was silly enough to give me a course to teach) would never use a raw pointer or a C-style array in their first year.


Steve Love

Posts: 20
Nickname: essennell
Registered: Sep, 2004

Re: The miseducation of C++ programmers Posted: Aug 18, 2005 7:20 AM
Reply to this message Reply
http://www.acceleratedcpp.com

Although it's marketed as a learning book, it's got some goodies in it for veterans as well.

Tanton Gibbs

Posts: 20
Nickname: tanton
Registered: Aug, 2005

Re: The miseducation of C++ programmers Posted: Aug 18, 2005 8:00 AM
Reply to this message Reply
I teach an Advanced C++ course where I work. It is amazing how many C++ programmers have no grasp of templates, the STL, or even how constructors and destructors work. We dive headfirst into it, and they learn quickly, but I would love to see it taught earlier.

Harrison Ainsworth

Posts: 57
Nickname: hxa7241
Registered: Apr, 2005

Re: The miseducation of C++ programmers Posted: Aug 18, 2005 9:22 AM
Reply to this message Reply
It is easy to be ambivalent about templates. They are almost/sometimes necessary in C++. But they are undoubtedly evil!

And once you use other languages they can only seem unlikeable.

Teaching them should be in the form of a small set of usage patterns. That way the usual benefits of patterns generally can be gained, and the abstruse and recherché details can be avoided. Not everyone should be venturing into the heart of template darkness...

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: The miseducation of C++ programmers Posted: Aug 18, 2005 9:26 AM
Reply to this message Reply
> It is easy to be ambivalent about templates. They are
> almost/sometimes necessary in C++. But they are
> undoubtedly evil!

What is an array if it is not a template? An array is a type parameterized over some other type. Nothing evil about it. Just a specific case of a template.

Vesa Karvonen

Posts: 116
Nickname: vkarvone
Registered: Jun, 2004

Re: The miseducation of C++ programmers Posted: Aug 18, 2005 11:48 AM
Reply to this message Reply
If you google a bit, I'm sure you can find articles that explain why arrays in C and C++ are evil.

Zeljko Vrba

Posts: 10
Nickname: zvrba
Registered: Aug, 2005

Re: The miseducation of C++ programmers Posted: Aug 18, 2005 10:37 PM
Reply to this message Reply
For a long time I don't like the usual curriculums taught on C++: classes, inheritance, protection, friends, virtual functions and then maybe templates. I think that students should be introduced to the OO part of C++ at the very end of their course. Good OO design is something you cannot learn in the course - it takes time and to see many good and bad examples.

When I was learning C++, most of my time I have (uselessly!) spent on deciding about protection levels, class hierarchies that never quite come out properly, etc.

What I was trying to accomplish with inheritance and virtual functions was actually genericity. And templates are much more suitable for this than OO.

I have been exposed to several functional languages, Ocaml (http://caml.inria.fr) and Scheme among others, and my current C++ programming style reflects my 'functional' thinking. In C++, templates make it relatively easy to program in functional style, although the syntax is much uglier than in e.g. Ocaml.

Now, when designing something new, I rarely mess with the OO part of C++ - I'm mostly using templates to achieve genericity and static polymorphism. And "function objects" can serve as a poor man's closures.

If I were to teach C++ to students who have already been exposed to C or other C-like language, this would be the order of topics:
1. memory allocation with new/delete/delete[]; references; function and operator overloading.
2. brief introduction to enhanced structs (briefly mention methods, constructors, destructors, that the struct name is a new type without the typedef). i would not mention classes and protection levels.
3. introduce struct and function templates, why to use them
4. introduce STL and many problem-solving exercises using STL
5. introduce boost and boost::bind and boost::lambda at least
6. show how to define your own generic algorithms and data-structures, in effect extending the STL. the point would be to show how to "abstract-away" relevant implementation details into policies. I find it much easier to abstract-away what is generic (e.g. comparison function in std::sort) than designing a proper class hierarchy.
7. iostreams (IMHO, they're really useful when you are doing more advanced stuff; for ordinary I/O C-style is IMHO much easier and controllable).
8. classes, protections, inheritance and virtual functions.
9. a bit on design patterns

I would spend perhaps 75% of the course time on topics 3-6.

Well.. this was a bit long.. just my 2 cents :)

Max Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Re: The miseducation of C++ programmers Posted: Aug 22, 2005 3:59 PM
Reply to this message Reply
I learned C++ by purchasing a textbook from the local community college (I'm now a Comp Sci student at the local university, testing out of classes left and right). That book was the second edition of "Computing Concepts With C++ Essentials," and I have to say that I got very lucky. Horstman has enough sense to realize that *using* a class or template is a very important skill to teach -- even before students learn how to actually *define* classes and templates.

It seems to me that primitives are taught so early only because doing otherwise would confuse beginning programmers ("what's that 'int' by obj.i?"). However, only the *bare* *minimum* about primitives should be taught because they are incredibly low level.

Howard Lovatt

Posts: 321
Nickname: hlovatt
Registered: Mar, 2003

Re: The miseducation of C++ programmers Posted: Aug 28, 2005 5:24 PM
Reply to this message Reply
A couple of Java centric comments on Chuck's well written article:

1. The Java world is about to tackel the issue of how to teach Java with the introduction of generics. I would suggest that they should take Chuck's advice and stop teaching arrays and primitives and instead stick to Objects and generics for beginners.

2. Java provides an ideal language that is easy to use like Python and runs as well as C++. Therefore one language can be both your beginners/testers language and your powerful developers language.

Flat View: This topic has 8 replies on 1 page
Topic: Policy Based Range Checking Class for C++ Previous Topic   Next Topic Topic: So what's HeronScript?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use