Live data from Hacker News

Why C++ is vastly superior to C

warp.povusers.org

81–90 of 123 posts

Re: Why C++ is vastly superior to C

#81
post #32

My reason why C++ is vastly inferior to C: It's just too goddamn easy to make a mess in C++ without noticing it. In C, if you make a mess, you will more likely notice it before it's unmanageable.

Can you be more specific?

I have a counter example (assuming I've understood you):

/* C /

int foo () { FILE x = fopen("bar"); return 0; }

/* C++ */ int foo () { ifstream in("bar"); return 0; }

Re: Why C++ is vastly superior to C

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

c and d are considered equal, you have overridden the boolean operators, what the code is actually calling on your if statement is:

c.bool() == d.bool()

In this case both will return true since they are non-zero, and thus the statement would be

1 == 1

Which is true; the compiler did exactly as you told it to do.

Re: Why C++ is vastly superior to C

#84
post #73

Earlier quoted context omitted.

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)

In C, 0 evaluates to false.

Re: Why C++ is vastly superior to C

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

Generally, people on Linux will be compiling using Makefiles, so just use make -j to speed it up.

Using -j with C++ builds will always still be significantly slower than using -j with C builds.

Also, I believe the rule of thumb for the -j argument tends to be 2 times your number of cores. A surprising amount of build time is often spent on disk I/O, so you see worthwhile gains for quite a while running more jobs than cores.

Re: Why C++ is vastly superior to C

#86
post #32

My reason why C++ is vastly inferior to C: It's just too goddamn easy to make a mess in C++ without noticing it. In C, if you make a mess, you will more likely notice it before it's unmanageable.

Can you be more specific? I have a counter example (assuming I've understood you): /* C / int foo () { FILE x = fopen("bar"); return 0; } /* C++ */ int foo () { ifstream in("bar"); return 0; }

C assumes that you know the contracts that calling a function implies. fopen()'s contract requires you to close the file after you are done with it.

Re: Why C++ is vastly superior to C

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

"C is simplistic and can be considered dead the day C++ compilers catch up with speed and memory allocation"

Those really are not the problems that are most pressing with C++ in the embedded field. Comparable speed is rarely noticeably different provided you avoid certain key things, and you can always just swap in a new allocator if you want.

Re: Why C++ is vastly superior to C

#88
highly opinionanted article. C++ breaks at places, where the compiler is instructed to not optimize (debug builds), and say operator overloading have been used for simple types, which creates function calls, rather than inlining it, while "C" approach (functon calls) would've worked not so slow. Talking from real experience, after coworker rolled heavy templated C++ math library for all consoles and PC, that worked very good in release, but debug builds crawled to 10 times slower.

The problem is that this library forced everyone to use it's types, interfaces, etc. - so the effect was spreading everywhere. Instead you should only do such things isolated, and provie "c" interface (for example zeromq does that).

Also do not propagate exceptions to client, especially if you are some middleware not used for the core of the things (for example social service api, advertisement api, or anything small used just as service).

Better do exceptions internally, and provide error codes or callbacks for client. Exceptions do not work on certain very popular gaming devices for examlple, and the user of your library might want to avoid them for other reasons

so do your best C++ in secret, if you want, provide us C interface

Re: Why C++ is vastly superior to C

#89
post #82

This article should be "why C++ is vastly superior to C for multiplying and adding 3 matrices if you're not a very good C programmer ".

So how would a very good C programmer implement this example? I don't think you can No True Scotsman your way around RAII and templates.

Re: Why C++ is vastly superior to C

#90
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.

often it's the implementation for certain platform that limits you, choices of what the C++ supports decides by the platform vendor - for example exceptions, rtti, or even up to date compiler.

another provblem arises due to the decoration, mangling of c++ symbols (while c externs do not have this problem), and sometimes this is problem even with two different versions of the same line of compiler

another one is the runtime incompabilities (exceptions again) and different compilers.

this problem is so bitchy, that if you have to develop plugin for maya, motion builder in c++, you have to use the same compiler the products were compiled with, which is not the case for a lot of the infrastructure, os out there...

Post reply on HN