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.

I program in C mostly. However, it is pretty obvious that many more commercial applications are done in C++.

As far as I can tell, C++ is a very complex language, with seemingly convoluted syntax and too many constructs. C++ also encourages the abuse of Objects where structs and functions will do. In fact, the only significant advantage I see in C++ is the use of templated generic types (though, according to the developers of Go, generics are bad for programs).

Basically, my question is, did I miss something? Or is C++ more popular purely by merit of luck or marketing?

Edit: I'm sorry that I apparently asked a loaded question; in retrospect I can see that the way I worded it appears to be complete flamebait.

What I meant was, since C++ has so many different constructs and paradigms available to it, why hasn't it been replaced by languages that do less but are better at that specific thing? For instance, both Java and C# are much better suited for OOP than C++ is, while C is much simpler for system-level programming, and something like lisp is more suited for functional programming. Why is C++ used over one or more of these other languages?

share|improve this question
    
I think you're mistaken, Go's developers are considering adding generics. C++'s template system is very powerful and very complicated and much more than just generics. –  jozefg May 19 '13 at 5:43
5  
When contemplating ugly constructs in C++, you should probably take a minute to consider how you would solve the problems they are intended to solve, in C. You might find the results even uglier. –  Carson63000 May 19 '13 at 8:09
3  
@Mat: Different people are different. I thought C++ was a hideous mess before I learnt it, then I learnt it and found that in some places it wasn't as bad as I thought and in others it was worse. For "high level OOP" other languages are much cleaner (C#, Java) and for "low level non-OOP" C has less traps for the unwary (which is a scary thing given the number of "traps for the unwary" C has). –  Brendan May 19 '13 at 14:22
3  
This could have been a constructive question if you'd avoided the whole "C++ is ugly and complex" bit. –  Robert Harvey May 19 '13 at 16:15
1  
@RobertHarvey Agreed. Please see my proposed edit, which removes some loaded words. –  Andres F. May 19 '13 at 17:49
show 3 more comments

closed as not constructive by gnat, Kilian Foth, BЈовић, Robert Harvey, delnan May 19 '13 at 18:08

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.

2 Answers

up vote 16 down vote accepted

Basically, my question is, did I miss something?

I believe you did, but it has less to do with programming languages and more to do with the human tendency to denigrate the unfamiliar. We do that. It's natural. Rising above it takes a willingness to endure the cognitive dissonance that comes with the comparisons to the familiar when learning something new.

You're doing two things you shouldn't:

First, you're looking at one language through the lens of another. One of the things you'll start to understand as your horizons become broader is that programming languages are just toolboxes with variations on the same set of familiar tools. The variations exist to solve specific problems. Some toolboxes contain basic tools that force you to do a lot of things yourself; others give you things to make certain complex tasks easier. My wife, who makes jewelry, has a dozen pairs of pliers that have very unusual jaws designed to solve specific problems. To me they're just funny-looking because her problems aren't mine.

Second, you're looking at every tool that's not already in your toolbox as something ripe for abuse because it doesn't fit your concept of "how it is." I have news for you: anyone with a lot of experience in a language can find a way to abuse any of its constructs. C -- and don't get me wrong here, because I've written a ton of it -- is especially rife with opportunities for abuse. Writing C is like owning a chainsaw: it's a great tool for removing unwanted limbs, but the line between use and abuse lies in whether those limbs are attached to your trees or your neighbors. Constructs that enforce better behavior are the equivalent of adding blade guards and chain brakes to chain saws: they were put there by the more-disciplined to keep them from having to clean up the messy results of the less-disciplined abusing their tools and hurting themselves or others. A little light bulb will go on above your head the first time you realize you can do a complete reimplementation of a class without having to wonder if any other code is getting away with directly writing structure fields instead of calling the setter function you so thoughtfully provided.

Or is C++ more popular purely by merit of luck or marketing?

None of the above. C++ is in wide use for the same reason as any other popular language: people have found it a useful tool for getting things done.

share|improve this answer
1  
Not to detract from your answer (which has my +1), but I think C++'s merit as a useful tool wasn't the only factor. I read somewhere Stroustrup lobbied pretty hard to get key people to use C++ (even throwing hissy fits when some of his colleagues from academia criticized the language). Can't find the link now, but it was in an article/blogpost by one of his colleagues. –  Andres F. May 19 '13 at 16:05
    
Aha! It was Ken Thompson (not from academia, my bad): "Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to [C++], to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said “no” to no one. He put every feature in that language that ever existed. It wasn’t cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that." –  Andres F. May 19 '13 at 17:14
    
Also by Ken Thompson: "In an interview I said exactly that, that I didn’t use [C++] just because it wouldn’t stay still for two days in a row. When Stroustrup read the interview he came screaming into my room about how I was undermining him and what I said mattered and I said it was a bad language. I never said it was a bad language. On and on and on. Since then I kind of avoid that kind of stuff." –  Andres F. May 19 '13 at 17:42
    
My point with all these quotes is that there is some evidence there was pretty strong marketing efforts to make C++ a success, just as the OP guessed :) –  Andres F. May 19 '13 at 17:44
2  
Stroustrup also said that there are two kinds of languages: the ones people complain about and the ones nobody uses. –  Blrfl May 19 '13 at 18:48
show 7 more comments

People want to use OOP. Also programmers want to learn as few new things as possible. Thus, when C++ first came out. It gained massive popularity thanks to backwards compatibility with C and because it implemented OOP, which was gaining massive popularity at the time. This popularity created so much momentum, that it maintains lots of it right until todays.

[opinion]

But todays, many better OOP languages exist and there is much less emphasis on backward C compatibility. I would reccommend looking into Java, C#, Python or Ruby for modern OOP language.

[/opinion]

share|improve this answer
    
Ruby should definitely be in that modern section as well. –  jozefg May 19 '13 at 6:01
1  
@jozefg Well, Ruby is like different version of Python. –  Euphoric May 19 '13 at 6:02
    
I'm gonna disagree as a Python programmer who's poked several times at ruby. But it's not really relevant anyways. –  jozefg May 19 '13 at 6:04
8  
OOP is the least important feature of C++. Modern C++ code is very far from the OOP principles. Just read what Stepanov, the author of STL, say about OOP –  SK-logic May 19 '13 at 10:52
6  
@Euphoric, do you equate classes (a pretty low-level feature) with OOP (a comprehensive design methodology and philosophy)? In STL, Boost and alike, classes are nothing but types and modules. Nothing to do with OOP. –  SK-logic May 19 '13 at 11:01
show 5 more comments

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