Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

My school starts the computer science curriculum with C++ programming courses, meaning this is the first language that many of the students learn.

I've seen that many people dislike C++, and I've read a variety of reasons why. It almost seems to be popular opinion that C++ isn't a very good language. I get the impression it's not very liked based on some questions on StackExchange as well as posts such as:
http://damienkatz.net/2004/08/why-c-sucks.html
http://blogs.kde.org/node/2298
http://blogs.cio.com/esther_schindler/linus_torvalds_why_c_sucks
http://www.dacris.com/blog/2010/02/16/why-c-sucks-part-2/
etc.

(Note: It is not my opinion that C++ is a bad language. In fact, it's the main language I use. However, the internet as well as some professors have given me the impression that it's not a very widely liked language. In fact, one of my professor constantly rags on C++, yet it's still the starting language at my college!)

With that in mind, why is this the first language taught at many schools? What are the reasons for starting a programming curriculum with C++?

Note: This question is similar to "Is C++ suitable as a first language", but is a little different since I'm not interested in whether it's suitable, but why it's been chosen.

share|improve this question

closed as not constructive by Thomas Owens May 1 '13 at 17:49

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

6  
Which schools & where? All the ones near me (3 in town, and a few others within a couple hours' drive) teach Java as a first language. C++ comes in in the last year or two (depending on which courses a student takes). It's been that way for at least the last 10 years. –  FrustratedWithFormsDesigner Jul 25 '11 at 17:57
37  
"C++ isn't a very good language": it's so bad that most software products you use in your daily life are written in C++. –  MainMa Jul 25 '11 at 17:58
7  
Professors are like other programmers in having only moderately rational likes and dislikes. At the same time, they are like students in being experience-deprived. –  Mike Dunlavey Jul 25 '11 at 18:00
4  
@FrustratedWithFormsDesigner please dont be stupid. you know what he clearly is asking. did your elementary school never give you math questions with extra information. learn to read through the extra bits to the root of the question. if you are here just to nitpick; kindly see yourself to the back of the room. –  dustyprogrammer Jul 25 '11 at 18:19
4  
In first year, it's all about separating the wheat from the chaff. –  Steve Evers Jul 25 '11 at 18:22
show 18 more comments

15 Answers 15

Every single language has a cult following of lovers and haters alike; this is true of C++, Java, C#, Haskell, Objective-C, whatever.

There are many valid reasons to like or dislike a language.

In the end, there are a few reasons why C++ is predominantly taught in universities:

  • It builds on top of C; therefore, the transition from C to C++ is not too painful. Quite a few universities teach C before C++ (which makes a lot of sense IMO).

  • It's one of the most popular languages in the industry (that's starting to change with Java, mobile development, web development, etc. but it's still up there)

  • It's a language that was written by an academic, for academic (ie research) purposes; therefore a lot of professors use it on a day to day basis and are very familiar with it, which makes it an obvious choice for the content of their course.

Don't be too hasty in dismissing it as a "bad" language; I recommend you dive into it, really learn it, build some moderate to large sized projects using it. Then do the same with other languages; at that point you'll have enough experience and insight to say "I think C++ is bad because X, Y, Z" or "I think C++ is good because A, B, C which Java doesn't have".

You still have a lot to learn, young grasshopper.

share|improve this answer
    
It may not be a "bad" language if you ascend to the "bad is subjective" philosophy, but for virtually every combination of technical concerns, there is a more-productive, safer language. In my opinion, the reason C++ is taught is because it's what people use, and it's what people use because it's what people know, and it's what people know because it's what universities teach. Aside from popularity, C++ has no substantial merit that I can see, and I program with it professionally. –  weberc2 May 10 '13 at 21:46
add comment

Simply put, it's a very good teaching language because it doesn't hold your hand. People who learn to drive on a manual transmission have almost no trouble their first time in an automatic, but the reverse is not true. It takes longer to learn, but in college you have 4 years of toy programs to practice on before you have to make anything useful.

share|improve this answer
9  
I’m worried by the fact that this false analogy has garnered so many upvotes. This isn’t how learning works. One of the many misconceptions of didactics. –  Konrad Rudolph Aug 26 '11 at 13:00
add comment
C++ isn't that bad. 

What is being taught in school is usually driven, by what the professors know, and what was being used in the industry and popular at the time.

Think of schools as a time capsule to the past. :)

I really wish it was the other way around.

share|improve this answer
    
a very sensible point ! I was not given any exercises on smart pointers or RTTI or RAII in college. WTF ! –  Wildling Oct 7 '12 at 18:40
add comment

English has also been described as a really bad, hacked together, inconsistent language, but since so many people around here know it, my parents and teachers decided it was a good idea to teach it to me.

I think it's the same with C++. It's a language that a lot of people know, so it's worthwhile getting a basic fluency.

It also has the advantage of being low level enough to really give you a feel for what's going on at the hardware level.

Finally, it doesn't have the "commercial" issues that some other languages have (like Java-Oracle or .NET-MS). I know a lot of universities wouldn't want to be accused of teaching one specific company's product over another one.

share|improve this answer
    
+1 for c++ not being a commercial language. It is good to learn a language without worrying abt the politics and business tactics. <installing Java7 on Linux for example> –  Wildling Oct 7 '12 at 18:41
add comment

If C++ is so bad, how do you explain that most software products you use in your daily life are written in C++?

There may be several reasons to learn C++ in college from the first year:

  • It's largely used. The existing codebase is just huge, and even now that there are languages as Ruby, Python or C#, C++ is still used a lot even when creating applications from scratch, including for the websites. In this case, learning C++ is a good choice. At least a better one than spending two years learning Ada, i.e. something you will never use in your life, unless you develop applications for spacecraft.

  • It's not too abstract. For example, how can you explain to students what are pointers if they've learned only C# or Java?

  • It is difficult enough compared to, say, PHP. It means that students who are not made for programming will leave soon, which is not so bad and avoids for a student to waste two or three years before understanding that software development is not for him.

This makes C++ more suitable than Ada, Java or PHP.

share|improve this answer
1  
It seems like C would be better for your second two points. Are there schools that teach Ada? I would definitely take that over C++ but then again I'm weird! –  Jetti Jul 25 '11 at 18:18
    
C++ is selected for commercial products because it's what more people know, not because of its technical concerns. C++ is an unsafe, hard to use language compared to many modern languages. Languages aren't selected on their merits but because they're popular. –  weberc2 May 10 '13 at 21:50
    
Furthermore, I can't think of many things Ada does worse than C++, and I would much rather use it than C++ (my code would be simpler and safer, anyway), and I program in C++ professionally! And for teaching students about pointers, there's always Ada, Go, or any of a number of sane languages. And regarding your last point, C++ is needlessly difficult. Many of the problems C++ programmers face have nothing to do with programming, but with overcoming C++. Programming at any level is fairly straight forward in a sane language. –  weberc2 May 10 '13 at 21:56
add comment

Generally speaking, if you can learn and master C++, you can learn and master pretty much any other language out there. The reason it's disliked is because, in order to be proficient in it and have a fast release time, you need to be very familiar with the language and it's standard library.

However, in a language such as Java, you can have a fast deployment time with only some advanced knowledge of the ins and outs of the language/standard library. Hell, I only know like five things from the Java standard library by heart (asides from the basic stuff like collections of course).

That being said, C++ is still a widely used language because of it's great combination of speed and object-oriented methodologies. While many people believe it's not full OOP, I believe it gives you most of OOP's flexibility without forcing you to be a total fanatic. Most compilers even allow you to write pure C.

If I had the choice, I'd take C++ over Java any day, but that's just me being a fanboy. Generally speaking, Java is useful because it will run on pretty much any architecture that has a Java interpreter built for it. So for client applications that need to be supported on multiple platforms, it's considered the best tool for the job and most new applications written are web based anyways.

share|improve this answer
    
It may not be true of the object code, but the promise of C languages including C++ back in the day was that there were compilers for just about every platform so the same source code could be used to compile applications for a wide variety of platforms. –  JohnFx Jul 25 '11 at 22:34
    
That is in-fact true. Most *NIX platforms have built in compilers and that tends to have a psychological effect on most people in the form of "Sure, I could download THAT compiler, but this one came with my OS so surely it must be the best". –  David Young Jul 26 '11 at 2:00
    
You should try other languages besides Java--there are alternatives that make up the best of both worlds. Go for instance offers speed, portability, and simplicity and it makes concurrency a breeze. –  weberc2 May 10 '13 at 21:58
add comment

As some of my professors have told me, it is easier to start from the bottom, or a low level, and then work your way up. A language like C++ gives you a great introduction to what being a computer scientist is really about. It may not be as glamorous a language as Java, Python, Ruby, etc... but it allows you to gain a core understanding of important program features such as pointers and memory management. Even if it is not a language you plan or want to use for the rest of your life, you will appreciate in years to come when you start to find your desired programming path.

share|improve this answer
    
This sounds like an argument for Ada, not C++... –  weberc2 May 10 '13 at 21:59
add comment

C++ can be one of the simplest languages for beginner level console programs. Sure the language is complex, but you can focus on a procedural subset. You can ignore the existence of pointers for quite a while. You can start of simple, then build.

There is less "fluff" syntax for getting that initial "hello world" program up and running compared to java or C#. Should a beginner have to see the word "static" for a hello world app? In java/C# they do.

share|improve this answer
add comment

C/C++ is actually a better language than most others, firstly because it does not add a false sense of security. Secondly because you have tho know what you're doing.

I actually love the language, and I consider it superior to most alternatives.

It's also as productive as most other languages, and not that "crashy" if you know what you're doing, and think before you copy-pasta random codez.

Also a good read - http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

However, some things in C++ are actually bad, for example exceptions, and unintuitive overhead in some cases. This is the reason, I guess, why Linus is so negative about it in the post you quoted.

A good read to touch one of the related topics - http://blogs.msdn.com/b/oldnewthing/archive/2004/04/22/118161.aspx

share|improve this answer
2  
This answer is just completely wrong. First and foremost because there is no language called “C/C++”. –  Konrad Rudolph Aug 26 '11 at 14:46
add comment

When I studied computer science, Java was tought first, but my university right now teaches two languages to us computational linguists: first Prolog and then C++.

C++ is taught for (at least) the following reasons:

  • It's a general-purpose language, you can write software for any operating system with it (because there exist many compilers). It is designed to be a good production language, it makes it easy to re-use program parts, interoperate with real-world hardware and software, etc.

  • It's really fast. You can't use Python or Scheme or Prolog for processing huge data sets, which are common these times. Think graph algorithms with millions of nodes. (That's also why computer games are usually written in C++.)

  • Students can learn what the compiler does. Actually, as long as I only learned Java (starting in high school), the compiler's work always seemed like magic to me. You just don't learn about the stack and heap, the whole static vs. dynamic linking thing, etc. as a Java beginner. C++ de-mystifies the whole computer.

  • For what it can do, it is ok in learning time (although it is probably one of the most complicated languages if you really dig into it). It offers a nice library which helps with a smooth learning curve. (There are different approaches to that, though. In my university, we were taught how to write our own string classes and smart pointers before we were allowed to use the library; Bjarne Stroustrup, the inventor of C++, encourages the opposite order.)

share|improve this answer
    
This doesn't explain why Ada, for instance, isn't taught as the first language. –  weberc2 May 10 '13 at 22:06
add comment

Earlier there was Pascal, earlier Pascal there was a something alike Basic. The interesting part is - what next ? Maybe nothing. I have an though about "why c++". Because it's hard but it's not to hard alike lisp. No, I really understand that C++ is good language for system programming, I know that there area lot of projects coded on C++ and there a are tons of libraries so the students can create everything with it. But we are talking about students and their possibility to create logics and understand the system. You can't be a good C++ coder if you can't create simple logics and understand how the system works and that is a main reason in my opinion. And yes, another simple reason is stable career start.

share|improve this answer
add comment
  1. Professors don't like to prepare a new course and there are limits to how much you can offer.
  2. Languages come and go, so they gave up trying to stay on the cutting edge (See #1)
  3. It's a university and not a technical school. More focus on providing a foundation than job training.
  4. Covers a wide enough range of programming: server, desktop, embedded, UNIX, Windows.
  5. They use it as a weed-out course. Every major area of study has at least one.
share|improve this answer
add comment

Um. C++ is not often taught as the first language in college (for BS Computer Science). Intro to Computer Science is more usually taught in Pascal, Java or C these days. My college used Scheme. You will see 1 to 4 other languages (including C++) through the other courses of degree studies.

share|improve this answer
add comment

The uninformed have perceptual flaws one of which includes the idea that C++ is a more difficult language (than others) thus those who "learn C++" are somehow smarter or better qualified. Discuss this with any recruiter or hiring manager. It's the same as other types of perceptual inflation (such as grade inflation, degree inflation, .... and applies to other majors as well with non-technical topics, such as "undergrad life science for non-science majors"). The perceptual flaw continues despite the fact that many proclaimed "C++ programmers" are actually C programmers who name their 99%-C-source-files with the extension .cpp. Because universities cow-tow to wider perception (includes hyped technologies, since universities want funding as well), this creates the tendency to learn non-useful skills like C++.

share|improve this answer
add comment

It is very depressing state of affairs when we condemn C++ based on some other language. I personally hate Linus's rant about C++, to me the whole argument is biased because when Linus wrote it, he had already created the kernel in C, and as with many programmers it is easier to rant about new technology rather than re-implementing a huge source code in a new technology. If somebody will ask Linus about Functional programming today, he will come up with a new rant.

C's rise to popularity was basically because of compiler availability on embedded systems. I have written compilers and let me tell you from experience writing a C++ compiler is many orders of magnitude more difficult than writing a C compilers. Popularity of Lua also shares the same advantage, a C compiler.

Now coming to your question, C++ is the most mature programming language. It has successfully evolved over time and also inspired other languages (Java/C#). I remember when Java 5 Tiger was released, all the good features of C++ were incorporated in it.

Java was unfit for functional programming, so they made Scala, C# was unfit as well, so they made F#, but C++ just incorporated then without a drastic change in C++11. As a matter of fact C++ would be the first language I would teach my son.

In the end it does not matter how big you are (IBM, Microsoft) but it matters how well can you adapt (Google, Facebook)...

share|improve this answer
1  
Beyond the dubious assertion that "C++ is the most mature programming language," this doesn't attempt to answer the OP's question. –  Caleb May 1 '13 at 14:18
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.