Matt’s Thoughts on C++

This started out as a comment on Joe’s post about C++, but it started getting long.

There are really two issues here.
(1) How to learn C++.
(2) How to understand this group’s code, which mixes C and C++ approaches.

I have a preferred way to teach C++ as a first language: teach it as a procedural programming language, but with all the STL features.  Then gently explain how classes and templates make this all possible.  This avoids rushing through C, teaching people to use unsafe strings and arrays without properly warning them about how easily they break, on the way to classes and templates.  This is the approach taken in Accelerated C++ by Koenig and Moo.  (Which is getting a little long in the tooth, but still to my mind a great book.)

But hardly anyone is coming to this with no programming knowledge.  I suspect there are three basic categories of people coming into the group: people who know several languages already,
people who know one or two languages including C, and people who know only Matlab.  The first category of people needs only an introduction to the codebase and a stern reminder that reading the source is the only way to wisdom.  The second group needs an introduction to the object-oriented paradigm and its implementation in C++, concurrent with an explanation of how our code works.  The third group needs an explanation of the environment (compilers, linkers, libraries, makefiles, command-line arguments) and the language, before diving into the code. For this group, I think an Accelerated C++ type of approach might work very well.  People who are familiar with classes, strings and vectors can pick up structs and C-style arrays pretty quickly.  The main  downside is that there’s a delay before new group members can productively engage with the code, while they learn the nuts and bolts of C++.

If we wanted to be C puritans, there’s a very good tutorial still under development at

6 thoughts on “Matt’s Thoughts on C++

  1. I agree that procedural C++ is the way to go. Most of the arrays and file i/o that we use is from C++ anyway, and much of the rest of our stuff is not specific to either language. I think especially for first-time coders, C++ is more intuitive to learn.

    The only tough C-specific thing in the models I use is passing around pointers to structs (as opposed to classes in C++). This would be for more advanced users, and I think coming at it backwards is fine. Most of our code does not emphasize classes and data structures — but in the future we, and our trainees, may want to go this direction.

    P.S. I would like to enroll in the Dr. Woodruff tutorial on “compilers, linkers, libraries …. etc.”

  2. Procedural is likely a good way to start. Once you’ve written a few programs you’ll start to see patterns that can be converted to classes. In this way the class seems like a natural solution, rather than some abstract thing looking for a problem to solve.

  3. Pingback: Thoughts on Learning C++ « Pat Reed Group Research Tips Blog

  4. Pingback: Getting started with C and C++ – Water Programming: A Collaborative Research Blog

  5. Pingback: Water Programming Blog Guide (Part I) – Water Programming: A Collaborative Research Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s