Live data from Hacker News

Why C++ is vastly superior to C

warp.povusers.org

51–60 of 123 posts

Re: Why C++ is vastly superior to C

#51
post #34

This post boils down to "Take C, add support for OO, a crapload of new syntax, standard library that 10x as large and ta-da! you can find problems which have simpler solutions than in C." There's a great post by Linus Torvalds about C vs. C++ in the kernel. Some excerpts: "My point being, that C++ adds absolutely nothing interesting." "C++ is a mess. There's no design. It's just "add crud on top of C". And the crud i…

The author of the OP has a pretty well written rebuttal to everything Torvalds has said about C++: http://warp.povusers.org/OpenLetters/ResponseToTorvalds.html

That article is not very informative, and spends a lot of time characterizing Linus as someone with the “C-hacker syndrome.”

Re: Why C++ is vastly superior to C

#52
I don't think any language is vastly superior to any other in every case.

You can say that C++ is vastly more powerful (and flexible) than C, but for low-level/embedded/kernel etc development, many would argue that C is the superior language.

Many people would also argue that C++ is maybe too powerful and complex; you can do everything with it, but sometimes this makes it hard to decide how to do "anything" (procedural ? Object-oriented ? Using templates ?).

Lots of people (myself included) find it so complex that they only use a subset of it - "the good parts". However, agreeing which parts to use is often impossible.

I've written about about what I consider "the good parts" here:

- http://www.ppcsoft.com/blog/c-star.asp

Re: Why C++ is vastly superior to C

#53
Counterpoint to the C++ fragment in "Error handling" section:

  void foo()
  {
    Matrix *a = new Matrix(1000, 1000);
    Matrix *b = new Matrix(1000, 1000);
    
    delete b;
    delete a;
  }
Pretending exceptions solve error handling gets you a big fat zero. Look at boost: despite being written by C++ experts and held up as an excellent library (which it is!), it contains exception-unsafe portions. Why? Total exception safety is just as hard as the original error handling problem.

Re: Why C++ is vastly superior to C

#54
post #24
post #20

Earlier quoted context omitted.

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

http://yosefk.com/c++fqa/defective.html isn't strictly limited to answering that question, but it touches on it a lot. I know I'm flinging links around a lot here, but, well, this is all well-covered ground.

Most of the points mentioned in that particular link pertains why both C and C++ are inferior to languages like LISP and Python which have garbage collectors, weak type system and the like.

The bitching about bad compile time errors has been mostly fixed in clang.

Then only _inconsistency_ (in the correct sense of the term) in C++ I am aware of is the unordered initialization of static objects. So if you have "class A { ... A () { } };" and have a "A foo;" declared somewhere with static linkage, it can be hard to pin down exactly _when_ that constructor will be called. It will be called before control is transferred to main, but you may want even finer control.

If you have noticed other inconsistencies I'd love to know.

Re: Why C++ is vastly superior to C

#55
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…

You don't get a warning because the program is doing exactly what you asked it to do. You said a C with x = 0 is equal to 'true'. And you said a D with f = 0.0 is equal to 'true'. By transitivity of equality ...

Re: Why C++ is vastly superior to C

#56

I've found that whenever someone argues "X is best", they've only worked in projects where "X" makes sense for them. At a start up a couple of years ago, we had an intern that was all hot and bothered over C++ and boost. After he expanded is horizons to web development and investigating scripting languages, he really enjoyed Ruby. It depends on what you are working on, the libraries and tools available, and your comf…

The answer to your question is "use Visual Studio." ;-) Or, at least, use clang. The gcc stack is pretty poor at dealing with templates, and its debugger is pretty baroque.

Re: Why C++ is vastly superior to C

#57

For some things, C++ is better than C. For some things Lisp is better than either, and for yet other things, Python is better than them all. Why are people so insistent on declaring their view is absolutely right, with no arguments, everyone else is wrong, and that one language will rule them all? Trust me. For some things I do, C is vastly superior to C++, but I'm not going to try to convince everyone that C is bett…

C and C++ have considerably overlap in use cases, which is what makes this argument valid.

Comparing C or C++ to Ruby or LISP is stupid.

Re: Why C++ is vastly superior to C

#58

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.

But you don't have it, unfortunately. At that level C is just as unsuitable. Time to break out your assembler. ;)

Re: Why C++ is vastly superior to C

#59
The RAII benefits are definitely there and STL containers are pretty awesome, but you can still create generic containers in C by using void pointers. For example, a simple vector API:

  typedef struct { void *elements; int elem_size; int n; } Vector;

  Vector *vector_new(int elem_size);
  void vector_free(Vector *v);
  void vector_push(Vector *v, void *elem);
  void vector_pop(Vector *v);
  int vector_size(Vector *v);
  void *vector_at(Vector *v, int i);
etc. This is off the top of my head, but you get the idea. You can basically put anything you want in there as long as you say how large the elements are upon initialization.

There is a good book on generic C programming: http://sites.google.com/site/cinterfacesimplementations/

Re: Why C++ is vastly superior to C

#60
post #40
post #11

Earlier quoted context omitted.

> If C++ was really "vastly superior" to C then why are so many people still using C and using it productively? Why are so many people using Java (perhaps even more than C and C++ combined)? Does it make a good language? Absolutely not. In the case of such simplistic languages as C and Java, it's their simplicity that makes them a popular choice. Productivity: I am not sure all the C folks are as productive as they c…

"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, because of often subconscious fear of inability to learn new stuff, and so on. 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.

Java is a terribly verbose and an embarrassingly simplistic language. C is simplistic and can be considered dead the day C++ compilers catch up with speed and memory allocation, which will make it suitable for embedded programming too.

(And BTW, I don't mind JVM, it probably is a fantastic piece of engineering, except... for reasons I don't understand very well, a simple "Hello world" application written for JVM can take seconds to load and execute. I've heard a thousands reasons none of which made much sense. As well as promises JVM will be improved in the future. First time I heard this was 15 years ago, still no progress.)

Post reply on HN