Live data from Hacker News

Why C++ is vastly superior to C

warp.povusers.org

71–80 of 123 posts

Re: Why C++ is vastly superior to C

#71
The problem with C++ is that the language is too damn big. This results in most programmers only learning really well a subset of the language.

Unfortunately, different programmers end up with different subsets.

I'd like to see some de facto standardization on subsets. For instance, there could be Basic C++. When programming Basic C++ you use it like C with the following C++ features added: constructors, destructors, references, std::string, and maybe the STL collections.

Simple Object C++ could be Basic C++ plus single inheritance.

The on top of that, we could add things like multiple inheritance, operator overloading, templates, and so on.

Re: Why C++ is vastly superior to C

#72
post #62
post #49

Earlier quoted context omitted.

That is exactly what I'm saying. Compilation of C++ is really surprisingly slow. Mostly because compilation of modern C++ code involves parsing tens of megabytes of headers that mostly use complex to analyze constructs. Fact that C++'s grammar and semantics are incredibly complex does not help fast compilation either. Separate compilation does not solve it much, because many simple changes, that affects only one file…

> Compilation of C++ is really surprisingly slow. There's definitely something to what you're saying here. Or, rather, maybe something a few years ago. However, I don't think it really applies so much in 2011. Computers have gotten big and fast to the point where this argument is pretty meaningless. Personally, I stopped caring about compilation time when I got a 3.6GHz i7 with eight in-flight threads. I'm OK with fe…

Concur. C++ compilation speed was legitimately a problem five years ago. Improved compilers, faster computers, and multi-core compilation have made it moot.

Often you'll see a C++ basher bring up compilation speed and then in the same thread advocate python + C as the happy medium, which I find crazy. C++ is so much higher level than C the need for scripting is often obviated. I've typically got about 2x SLOC expansion rewriting perl/python as C++, including stuff like headers, so really not much more code at all, just 100x faster and a tiny fraction the memory.

The other line you see, including elsewhere on this page right now, is that C and C++ are the right tool for the job in different domains. I really don't get this. C++ is straight-up a replacement for C. There is no C program that wouldn't be shorter and clearer rewritten as C++. The only occasion to not use C++ is when you don't have compiler support, which is extremely rarely a concern anymore. Even the lowest level embedded stuff is moving away from C in favor of C++.

Re: Why C++ is vastly superior to C

#73
post #43

Earlier quoted context omitted.

Maybe it's just coming from a dynamic language, but it appears that you've overridden the bool operators to always return true. (except when you pass in 0 and 0.0) If you redefine how two structs of different kinds are compared, who is the compiler to say it's a problem?

In most dynamic languages 0 is false and anything else is true but it normally wouldn't use that information to coerce two values of different types to booleans before comparing them.

I'm only aware of php and javascript equating 0 to false. But at any rate in this case it's not equating 0 to false, it's comparing non-zero to zero and returning true. (as it should)

Re: Why C++ is vastly superior to C

#74

Novice question: Why is C++ used for the vast majority of video games today? Why is it used for most commercial CFD codes? (A lot of codes in academia still use tons of legacy fortran though.)

I think this post sums it up pretty nicely: http://www.gamearchitect.net/Articles/WhyC++.html

Personally I think the advantages boil down to syntax and type-safety. For example, vector math is much more succinct and can be made type-safe. Constructors/destructors also can be handy for enforcing resource allocation.

Re: Why C++ is vastly superior to C

#75
post #20

Earlier quoted context omitted.

What are some of these C++ features that interact in unpredictable ways? Just curious.

Implicit conversions come to mind. They don't need to interact with anything to be confusing. Consider this program: #include using std::cout; using std::endl; struct C { int x; C(int _x) : x(_x) {} operator bool() const { return 0 != x; } }; struct D { float f; D(float _f) : f(_f) {} operator bool() const { return 0.0f != f; } }; int main() { C c(9); D d(2.0f); if (c == d) { cout g++ 3.4.4 doesn't so much as warn th…

In C++0x you can make those operator bool() explicit. Shouldn't have been there in the first place, and you still have to learn the difference between explicit and non-explicit operators, but at least now there is a way of making things behave.

Re: Why C++ is vastly superior to C

#76

Earlier quoted context omitted.

I think you know you've cracked when you prefer bad C# to clean Haskell.

Bad C# over bad Haskell, I think.

I have a... secret wish? private fantasy?... where I take a moderately complicated problem and outsource it to a known bad outsourcing company, but rigidly require that they write it in Haskell. Just to see what pops out.

Re: Why C++ is vastly superior to C

#77
post #71

The problem with C++ is that the language is too damn big. This results in most programmers only learning really well a subset of the language. Unfortunately, different programmers end up with different subsets. I'd like to see some de facto standardization on subsets. For instance, there could be Basic C++. When programming Basic C++ you use it like C with the following C++ features added: constructors, destructors,…

Most projects have a set of coding guidelines. I don't see why it cannot specify things like: "Don't use operator overloading!".

Google does, for one thing.

Without discipline both C and C++ will blow you up completely. With some discipline both the languages are manageable, and C++ more so; which is what the OP points out.

Re: Why C++ is vastly superior to C

#78
post #20
post #7

When the argument is that C++ has too many features that interact in unpredictable ways and are virtually impossible to get right, arguing that C++ is superior because it has more features is perhaps a fine argument in some hypothetical universe in which the primary objection to C++ is that it is missing features, but by failing to grapple with the points raised by the opposition in the real universe, you will fail t…

What are some of these C++ features that interact in unpredictable ways? Just curious.

Copy constructors are bad. Variable assignment should not be a user defined behaviour.

Re: Why C++ is vastly superior to C

#79

Earlier quoted context omitted.

I don't think this article is about declaring C++ the ruler of all languages. If you have an example of C being a better fit for a problem than C++, feel free to share it.

Embedded systems, 128 bytes of RAM. I really do just want portable assembly.

To put that in perspective, 128 bytes is an x64 program's stack's red zone. :D

Re: Why C++ is vastly superior to C

#80
post #60
post #40

Earlier quoted context omitted.

"Why are so many people using Java (perhaps even more than C and C++ combined)?" Well, one contributing factor is that a lot of universities now have a heavily Java based curriculum (turning their CS programs into vocational schools, but I digress). Another contributing factor is that Java has managed to carve itself a niche in which it is used extensively ("enterprise" applications - with all of the wonderful ambigu…

I know Java is practical within certain contexts and for certain class of people, but our judgement of what's good or bad in general shouldn't really be a matter of taste and preference. Are we an engineering discipline or what? What we call a matter of preference is actually things that go beyond engineering. We may have emotional ties to programming languages ("I love Java", "I hate C++") because of job security, b…

"our judgement of what's good or bad in general shouldn't really be a matter of taste and preference. Are we an engineering discipline or what?"

You know what. It's a funny thing, but as I was typing my response to your original post, I actually said this exact same thing to myself, and I started to think. It would be incredible if there was some non-emotional, non-touchy-feely way to get at the value of one language vs another. But then programming language choice just seems to be an inherently "feel" based decision...

"We should clean up the table from the psychological aspects of the matter and look at what's left: that's how powerful and how clever a language can be in the hands of a good developer."

This is one of the things that I thought of, but then there are so many demonstrations of people using all kinds of programming languages to do things that are incredibly clever and powerful.

Sometimes I like to just go through open source projects written in programming languages I am not extremely familiar with. I just want to get a taste of some of the myriad of programming styles and techniques that are out there. The different ways of looking at the same problem.

Even if I disagree with the method used, it is always eye-opening to see other ways of doing things - even some that may be vastly different from anything that I have ever seen before (my first time looking at Haskell comes to mind). I like to understand how and why different developers choose the routes that they choose.

I don't know, but to me it seems that, in a way, it is good that there is no emotionless method for rating languages. To declare one language as being definitively better than all others seems to me that it would be a tremendous loss. There is some value, I think, in having a diversity of "good" languages just for its own sake.

As to the simplicity of a language, well, to some people simplicity in a programming language is a beautiful thing, but then, the problem is that what constitutes simple is also a thing that varies from developer to developer. Perhaps the diversity of languages is a natural development from the diversity of programmers?

I think about Ruby. You know, when Matz describes why he created the language, he says that he wanted to create something that felt fun to develop in - fun for him. The fact that other people just happened to like Ruby was an unintended side effect.

I think that most people create a programming language with a similar type of outlook. They, either purposefully or subconsciously, try to build it to achieve a certain "feel". Perhaps it is this "feel" that makes a good developer powerful and clever with a language.

"for reasons I don't understand very well, a simple \"Hello world\" application written for JVM can take seconds to load and execute."

Heh heh, I have no comments on that.

Post reply on HN