The only bad thing about C++ is C

Pages: 12345
It compiles?
GCC wrote:
test.cpp:4:16: error: invalid conversion from 'int' to 'const char*'
Last edited on
Same here. I guess you are referring to the std::string(size_t n, char c) constructor, but the second argument doesn't have a default value (at least the standard doesn't define one).
@rapidcoder
Therefore C++ is *not* any safer than C.

I did not argue that, I only pointed out that your example was not idiomatic C++ at all.

As for the main topic of this thread, the common subset of C and C++ is just another tool in the box The bad thing about C++ is the amount of misguided or erroneous information about the language found in various textbooks and college courses. Some of it is misapplication of C idioms, but it's been decreasing (now we have misapplied Java and C# idioms instead)
The whole point of this thread is drivel: "C++ is stupid, particularly when compared to C."

Catfish is being his usual anti-C++ obstructionist/misinformist basher, and claiming the moral high-ground when he feels the need to (incorrectly) interpret Bjarne Stroustrup's statements for us. Stroustrup has never expressed anything of the following sort:
Because he realized, 30 years too late, that one can't build a high-level OOP language on top of C.
So he'd very much like to deprecate C to avenge his pains. Too sad he can't.
Putting little references in your drivel doesn't make it true -- something that has been noticed before: http://xkcd.com/906/
Who is using the strawman fallacy there, jerk? You can hardly say I have misrepresented you, as you were very explicit about (1) what you think of C++ and (2) what your opinion of BS's views are.

Joel Spolsky is known for his outspoken blogs. He is a competent software developer, but like every one of us, he has his opinion on things. Sometimes he hits it right on. Sometimes his own personal biases get in the way. One of his recurring idioms is to confuse levels of meaning in order to make a nebulous point.

Woah, so abstractions leak? And, wait, I actually have to know something about how the computer works to program it? *gasp*

If Joel learned to do it, why can't anyone else? I think that the only valid point he makes is that it is more difficult to code today -- but not because 'abstractions are leaking' -- rather, it is because we are working with more complex environments. Hey, maybe the C++ string class just might be useful after all.

C++ wasn't designed to replace C. It was designed to upgrade it. Hence BS's annoyance that the standards committees have been so antagonistic to bringing the languages together. On that point, he has been perfectly clear.


I realize I added flame-bait when I responded first time, and I'm sorry I did that. So I'm done here. I am not interested in reading the ad homenim and other anti-X nonsense that is sure to ensue.
C++ wasn't designed to replace C. It was designed to upgrade it.


Right, because an "upgraded" and "merged" C/C++ would never "replace" C.
Just because they never merged you assume deprecating C wasn't the intent. Well I assume it was.

Oh and flame bait? You're the one calling me a jerk after asking me to leave the forum for expressing something not to your liking. So chill.
closed account (43RGz8AR)
@vivmen Honestly I strongly disagree that C is the problem of C++. Like some one else on here said I believe C++ add enough of it's own problems. I guess, but really I don't view any thing in C++ or C a problem. If your looking for some kind of language that doesn't allow users to write crazy code, then I think the only way you can do that is find a "stupid" language. I do think C++ should have completely replaced C, but C is the core of C++. It would be hard to completely make C++ stand without it and for what point? C++ would be a completely different language then. C/C++ are complex and powerful languages because they allow a lot (At least I have come to learn). I do have to say that for C, I learned C++ and not C, every time I looked at purely C code it was a bit hard for it all to come to together. C++, I think really only allows nicer organization with OOP. Other then OOP I don't see a real bold difference.
Last edited on
It would be hard to completely make C++ stand without it and for what point? C++ would be a completely different language then.


It's a completely different language now.
Deprecating the C subset in C++ would be the right thing to do but Stroustrup can't bring himself to do it because they're not merged, and he has a thing for the name.

As for writing crazy code: it's easier when you have a legacy subset that doesn't interact well with the rest of the language, and is duplicated in function anyway i.e. it's useless for C++, and it's only there so that the compiler can chew on plain C code if it needs to. It shouldn't have to.

Which is exactly what this thread is about... a call for not using the C in C++.
So while Stroustrup advocates for a merge for his own reasons, I advocate for a schism (which is partly complete).
The annoying thing about C++ bashers is their flair for the dramatic. See Joel, Catfish and the FQA-lite. It's very hard to take any of it seriously if you call the "foo" + "bar" example a deal-breaker. The FQA-lite tries so hard to bash everything that it loses its purpose. If it were an actual objective-ish guide on which parts of the language are bad, dangerous or plain stupid, it would be a useful tool for semi-beginners like myself. Now, it loses all its value, because it's impossible to tell how grounded the argumentation is. The "foo"+"bar" example is clearly nonsense, but the FQA-lite uses more advanced examples, making it less likely for beginners to distinguish valid arguments from constructed scenarios that wouldn't/shouldn't ever take place anyway.

I think the biggest problem of C & C++ are its users. Part of them are doing their best to stay ignorant, the others are doing their best to keep away from objectivity, rather than just admitting that it has its flaws but is still a pretty damn good programming language. All this wasted energy would have been better spent bashing java instead!
@Gaminic, Try to define what makes a language good or bad. You know they are all Turing complete. I understand that complaining about "foo" + "bar" sounds silly, but there is something important here. It says that some things in C++ are falsely intuitive. C has less of that so people say that C is better. If you value other things, you're free to do that.
I can't say anything about FAQ-lite or joelonsoftware as I haven't read much of either.
I really hope that last sentence was a joke.
Not debating the fact that some things are counter-intuitive. I'm only saying "foo" + "bar" is a stupid example. That's like saying stoplights don't work properly because you can't see them when driving backwards at 200mph while blindfolded. Doing something nonsensical and not getting the result you for some odd reason expect isn't a sign of "bad design". Any scenario where you're driving backwards at 200mph while blindfolded is a scenario where you are doing something stupid, not the stoplight, just like how typing "foo" + "bar" is you doing something stupid, not C/C++. If there is no valid reason for a scenario to happen, there is no reason for the language to properly handle it.

Again, I'm limiting myself to the "foo" + "bar" example, not any general case. I do feel like it's useful to debate the "foo" + "bar" example as "Joel on Software" apparently found it a valid example to post and rapidcoder found it a valid example to quote.

(If this doesn't properly explain my case, I also have a "parachutes are stupid because they don't work when falling upward" example ready.)
I also agree that the C in C++ should be eliminated. Unfortunately, the C features are sometimes better than the C++ (such as the interface of printf vs cout when i18n is considered), and a large code base has been written using C++ constructs with C constructs. (For example, using strtok() with std::strings or using normal arrays of C++ objects.) As well, the most basic-looking syntaxes in C++ are those mapped to C constructs, like int x[10] being a C array, not a C++ vector.
Rather than eliminate the C in C++ it would be better to invent a new language ('C**'?) which maps the old C syntax to C++ semantics, except in the case of pointers, which don't belong in C++ anymore. E.G.
"foo" is now a std::string,
int x[10]; is now a vector.
{1,2,3} is also a vector.
int *s is now a syntax error. (maybe it can be used for something else)
printf() now takes an std::string, and has type checking (perhaps we can make a new syntax for declaring and using variable argument functions.)
Perhaps even a new print() function which eliminates the format algogether, but does not require tons of separate calls.
It's time to integrate STL into the compiler, while at the same time making the syntax more harmonious.
Last edited on
+1 rocketboy9k although I think someone already went through all that...

@ Gaminic: The "foo"+"bar" example demonstrates how the C subset breaks C++.

Same thing happens if you input two C arrays by hand then try to concatenate them into an std::string, if you want a more practical version of this example.

Then you're going to say "one should use std::string all the way". And I'd agree... but then why keep supporting ASCIZ C arrays?
Gaminic wrote:
I think the biggest problem of C & C++ are its users.


Aren't users the cause of almost all computer related problems anyways?
@rocketboy9000: You want to completely get rid of arrays and replace them with vectors? That's ridiculous. They exist for "entirely" different purposes. Yes, a vector can do everything an array can, and more. However, when you don't need the and more and you care about efficiency, you're better off with an array.

The whole problem with C++ [in my eyes] is that abstraction leads to improper use. Tell someone that a vector is a flexible array, and a week later you'll see a code snippet filled with fixed-size loops using push_back and linear searches calling erase(), topped off by the question "Why is my code so slow?!". You could say "Well, he's still in the learning phase!", but I can turn that argument around in favour of arrays as well. C++ and the STL are great, but in the hands of a beginner it's like giving a teenager a car: he'll honestly believe that it's "better in every way" compared to his bike, until he is faced with the insurance and gas prices. It's much easier to properly learn arrays first and then vectors than the other way around.

@Catfish: If you're going to input them by hand, you could have used C++ strings instead. If they were output from some other function, you probably used a C function that has a valid alternative. The C stuff is there for backwards compatibility. You can't mix apples and oranges. The only unintuitive things are the string literals, but when would you use them in a valid way?!
However, when you don't need the and more and you care about efficiency, you're better off with an array.

An intelligent compiler should optimize for this, transparently.
The STL itself is supposed to be highly optimized.

The C stuff is there for backwards compatibility.

This thread is about how C backward compatibility does more harm than good.
This thread is about how not relying on the C subset is mostly beneficial.
What is your stance on this?
closed account (1vRz3TCk)
I just can't help but think that removing C from C++ is akin to removing English from American.
In the end, C++ is just a language, and it's not fair to blame a language for bad code. It's the magician not the wand.

Also, how can you hate on C? It's the programming language of the gods, when they have the time for it :o
Last edited on
@Entire Thread: Let's all use some form of Java that gets compiled to machine code instead then :p
Java is deeply flawed compared to C++ not just because it is an interpreted language, but also because it does not respect functions the way it should:
- No function pointers leads to crummy syntax for functions that take functions (in C++ there should be function references).
- No non-member functions makes sine, a transcendent function that is implemented as one instruction, part of some stupid "Math" class, which is not cool.
Pages: 12345