Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm a 20 year C programmer finally making the transition to C++ and as far as I can tell the main advantages C has left are: * Faster compilation * Comprehensible error messages * No cout


I use C++ daily at work.

C++ code tends also to have a lot of allocations and data copying going on. I know you can get around those, but it seems like C++ programmers don't.

C++ looks nicer at first sight, but when you want to make sure error handling is correct, there's practically little advantage compared to C. Sure, C++ does have STL, but programmers still seem to occasionally allocate function stack and return a pointer to it and manage to do buffer overflows.

C has much simpler flow of execution. C++ exceptions mean there are eventually a lot of different possible code execution paths. In C, flow of execution is almost always simple and predictable.

C++ invites style where logic is spread over many layers of abstraction. It's often hard to see the whole picture of what's going on because of that. Instead you have to check all those constructors, destructors, watch out for inheritance, etc. In C, most related logic tends to be in same source file.

A lot of bugs I've seen in legacy code are related to these issues.


I have more issue with the poor performance of iostreams than with the interface, personally. Typesafe and type deducting string formatting is a pretty nice thing to have.


Maybe because iostreams are synchronized with stdio by default? It's possible to disable that for a big speed boost.

There's also the issue that iostreams might be implemented on top of stdio for simplicity. Hard to make it faster in that case!


Even then, it's pretty much the only place in the stdlib that extensively uses virtual calls, via std::locale. It's very complicated implementation-wise (I was actually working on an implementation of it once and it's not fun at all) and hard to find places to optimize it.

It's not that it's too heavy for a console app's output, really, but for things like converting numbers to strings and vice-versa (a-la boost::format) it is definitely a lot slower than atoi/sprintf.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: