Why Everyone Should Learn C++ First

About two weeks ago, an article from a blog I read fairly regularly made its way on to the Digg frontpage. It was the opinions of an experienced software developer about what programming languages someone who is just getting started in software development should learn. Many comments on this post questioned the omission of c/c++ from this list, which the author addressed earlier this week in this post. He argues that with the original post he was targeting people new to software development, and that he was of the opinion that programmers should get experience with a simpler language before diving into c++. There has been talk in the Georgetown Computer Science Dept. recently about making this same change, and starting with a much simpler language like Python, and a professor I know at another university is writing a book about Ruby aimed at beginning programmers.

I strongly disagree with this trend toward pushing beginning programmers toward “simpler” languages when they are starting out. I think learning c++ teaches certain programming concepts that many (and in some cases almost all) programming languages cannot:

Strongly Typed

C++ requires every declared variable to have a declared type, which brings with it several advantages. First, any type errors caused by things like trying to implicitly convert from one type to another or by calling invalid methods on a function are caught at compile time. This allows a developer to have much finer control over program flow, and reduces the number of possible run time exceptions dramatically.

Object Oriented

Anyone seriously interested in entering the world of modern software development must absolutely be familiar with the object oriented programming paradigm. This means that data can easily be represented in more complex ways, allowing a program to abstract data into more manageable forms. A program could for example, perform a series of functions specific to all pets, functions specific to dogs, and then functions even more specific to golden retrievers. C++ features support for all of the major aspects of object oriented programming, including public, private, and protected methods and variables, polymorphism (and even multiple inheritance, allowing a student employee to be both a subtype of student and a subtype of employee), and generic templates.

Procedural

C++ is also very well suited to procedural programming. Procedural programming replaces the objects, attributes, and class methods of object oriented programming and instead breaks tasks into data structures, variables, and functions (subroutines). By eliminating objects and their associated memory and processing overhead, well written procedural code is generally much faster than equally well written object oriented code. This functionality is particularly well geared to writing low-level applications like device drivers that need to be as fast as possible. Procedural programming is also excellent for quickly prototyping applications.

Unmanaged

Most modern programming languages have a feature referred to as “managed code,” which means that the compiler or interpreter automatically handles the allocation and deallocation of memory when a program runs using so-called “garbage collectors.” This eliminates memory leaks in a program, which is an excellent and useful feature.

As useful as garbage collection is, when someone is learning to program for the first time, any obfuscation of the way things work is not in that programmer’s long term interest. A C programmer (and c++ programmers to a lesser extent) knows the ins and outs of a computer’s memory system, and can pass pointers and pointers to pointers around with ease. This translates to being able to develop software that is fast, efficient, and that features well designed data structures.

  • http://regulargeek.com/ Rob Diana

    Wade,

    First, thanks for reading the RegularGeek blog. Regarding C++, I have always had the problem that it is generally overwhelming or a new developer. Eventually, yes C/C++ should be learned because of the memory mgmt features and just the need to learn procedural programming. Way back when I was a TA for an intro to C/C++ course, I focused on ensuring that people would stay in programming. Trying to keep people moving in that class is very difficult due to pointer manipulation and memory mgmt. I just wish there was an easier way.

  • http://regulargeek.com/ Rob Diana

    Wade,

    First, thanks for reading the RegularGeek blog. Regarding C++, I have always had the problem that it is generally overwhelming or a new developer. Eventually, yes C/C++ should be learned because of the memory mgmt features and just the need to learn procedural programming. Way back when I was a TA for an intro to C/C++ course, I focused on ensuring that people would stay in programming. Trying to keep people moving in that class is very difficult due to pointer manipulation and memory mgmt. I just wish there was an easier way.

  • http://wadetandy.com wade

    @Rob Diana
    Rob,

    Thanks for taking the time to respond. I agree that c++ does carry with it an initial “oh wow this is a lot” factor. However, having learned c++ as my first language (and also having been a TA for intro c++ courses), I have seen that it is something that even non-technical people can learn if it is taught correctly.
    The key, in my opinion is keeping things working at as high a level as possible until the syntax is properly learned. Back when I was in an intro class, for example, we learned vectors before we learned arrays. This allowed us to learn syntax and list processing without worrying about dynamic memory allocation or keeping a separate array size count.

  • http://wadetandy.com wade

    @Rob Diana
    Rob,

    Thanks for taking the time to respond. I agree that c++ does carry with it an initial “oh wow this is a lot” factor. However, having learned c++ as my first language (and also having been a TA for intro c++ courses), I have seen that it is something that even non-technical people can learn if it is taught correctly.
    The key, in my opinion is keeping things working at as high a level as possible until the syntax is properly learned. Back when I was in an intro class, for example, we learned vectors before we learned arrays. This allowed us to learn syntax and list processing without worrying about dynamic memory allocation or keeping a separate array size count.

  • Andre’ Toscano

    Let me ask you something, as a seasoned programmer that you seem to be. And please bear in mind that I realize this is a question with no straightforward answer.

    I’m new to any kind of C. And I’m planning on putting in the hours for the next couple of years to learn a language that can stand the test of time. I’m not interested in an “easy-to-learn-and-start-programming-in-just-24-hours” kind of deal. I would like to learn something that will enable me to be a good programmer in a few years time, not tomorrow.

    And from what I read everywhere, long term trends seem to point out that it’s either C or C++ or Objective C. (I’m not sure if these are variants of C, or if they just share similar names)

    From these languages, which one would you suggest I’d learn? Again based on the fact that I’m not expecting “exciting results” tomorrow, but am instead going for a strong knowledge base, from which I can then be better prepared to specialize in other stuff.

    Thanks. Any input will be great.

  • Andre’ Toscano

    Let me ask you something, as a seasoned programmer that you seem to be. And please bear in mind that I realize this is a question with no straightforward answer.

    I’m new to any kind of C. And I’m planning on putting in the hours for the next couple of years to learn a language that can stand the test of time. I’m not interested in an “easy-to-learn-and-start-programming-in-just-24-hours” kind of deal. I would like to learn something that will enable me to be a good programmer in a few years time, not tomorrow.

    And from what I read everywhere, long term trends seem to point out that it’s either C or C++ or Objective C. (I’m not sure if these are variants of C, or if they just share similar names)

    From these languages, which one would you suggest I’d learn? Again based on the fact that I’m not expecting “exciting results” tomorrow, but am instead going for a strong knowledge base, from which I can then be better prepared to specialize in other stuff.

    Thanks. Any input will be great.

  • http://nerdnewsandreviews.com Wade

    Hey Andre, sorry I’m just getting back to you. I’ve been reworking some things on my website and the e-mail post notification was apparently down. Hope you get this.

    It has been a while since I wrote this post, and while I still largely agree with it, I will say that it has some exceptions and caveats, and that in the end it really depends on what type of programming you are interested in.

    If you want to be a career software developer like I plan to be, are interested in all different types of programming from web sites to desktop applications to low level system programming, or and really want to understand how programs work at the deepest level, I think you should absolutely learn c++ first. It has all of the benefits I outline above and many more.

    Since you asked the question, I will tell you that C, C++, and Objective C, while being similar, are not the same thing. C is much harder to learn as your first language, in my opinion, as one must really understand everything a program must do, down to the tiniest detail to really be effective. It also has the drawback of not being object-oriented, which is essential experience if you plan to go into most development roles. Objective-C, like C++ is based on C, but it is primarily used for Mac OSX and iPhone/iPad development, and it does not have many applications beyond that in modern software (that I’m aware of).

    Once you have learned C++, I think C is also an extremely useful thing to know, and it will be a lot easier. I use both in my development job nearly every day. When you are at that point, I think you’ll understand when I say it that you will start looking at the task at hand and choosing the right language for the job. Once you’ve gotten a grasp on one language, particularly one like C++, it will not be very hard to jump to another. It really only takes me a few days of messing around with a new language to really understand it and be functional with it.

    If your main interests lie in web development and you don’t have any interest in anything else, I’d learn a language like Ruby, Python, or PHP. This doesn’t sound like where you are, but I thought I’d mention it.

blog comments powered by Disqus