C++ as an introductory programming language?

People who don’t like C often cite a move to C++ as being a better option. In reality it’s more like jumping out of the frying pan, into well, a larger frying pan. I’m not suggesting C++ is a bad language, because it’s not. What it is though is object-oriented. When teaching the concepts of introductory programming, there is no real place for OO. OO is an approach to software – it’s not the be all and end all. OO has been touted as a natural way to express concepts – to “think like an object”. But I don’t think it’s that natural. When I bake, I don’t think about the ingredients and implements I’m using as objects, because whilst in an abstract sense they are, in reality they are ingredients and tools. I don’t look at the wooden spoon and want to encapsulate functionality within it.

Now I have taught C as an introductory language for over a decade, and there are definite issues with it from a pedagogical viewpoint:

  • C’s compact and flexible coding syntax leads to clever, but often un-maintainable, code (at least by novices).
  • C’s I/O is marginal in terms of use and clarity, a significant drawback.
  • String and arrays are not easy to implement.
  • Restriction to pass by value parameters. In C, one must introduce pointers prematurely.

Now C++ does have advantages over C, dealing with some of these issues. It offers better I/O than C. It offers pass by reference and by value, pointers, exceptions and classes. The biggest problem with C++ is its complexity. The volume of its syntax and multiple uses of keywords easily lead to confusion. Sure, you could teach a subset of C++, maybe without the OO, but then you are effectively teaching C. As imperative languages touting the basic tenets of programming, the languages are EXTREMELY similar. Consider the two pieces of code below to calculate Fibonacci numbers: one in C, and the other in C++. The I/O statements are a little different, but otherwise in a procedural sense, they are both the same.


Fibonacci in C versus C++

Pedagogically I would steer away from both languages, and consider going backwards to Pascal or Fortran, or forwards to Swift, or maybe Julia. The rationale for an introductory programming course is to teach (i) problem solving by means of programming, and (ii) the fundamental concepts of programming languages. Coverage dedicated to OO concepts takes time away from the fundamental topics of programming: typing, control structures, modularity, AND some of the more maligned ideas: style, usability and testing, which are way more important than OO.



Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.