neuraleskimo wrote:A bit harsh toward your friend there don't you think?
harsh? My first sentence contains nothing judgmental, only a fact. You cannot be harsh when you give a fact or in that case you are not allowed to talk. I have no intention to school people. I am just interested about this topic. I even said to the guy that I respect his opinion but that I am not convinced by his argument that, like assembly, C is lower level.
What you said about <vector> reserving large chunks does not apply if elements are pointers or if the container is a list and not a vector. STL containers fundamentally use lots of dynamic memory. It is fundamental knowledge. Even if vector reserves large chunks, it still performs dynamic memory. An array on the stack in C does not allocate heap memory. And you have full control how you want to allocate on the heap if you want.
It is also fundamental that the memory allocator can stall other threads if you do many small dynamic memory allocations. If you are making an application that parses data spread over all threads, then you'd better not use STL containers.
By class bloating, I was referring to the OOP practice to have large structs with many variables that are unused just because it looks OOP.
The most common case for which C++ can be faster than C is when optimizing knowing better the types. But all the small layers like exceptions and functions embedded in structs will potentially make things slower. The amount of work to create a vector is huge. Many instructions. Same for smart pointers. Many things are added for this mechanism. If you are a good programmer you can skip smart pointers and be faster.
Only because of smart pointers and because of the syntax, I understand why people and companies prefer C++ over C. But it is more a cultural thing. In practical terms, one can do very good things in C with full control. It is not at all like using assembler and getting slow because being too low level. Of course the level of details can be high in C. But one gets used to it.
If you use gtest, you need to make your functions public and virtual to test them. Quite ugly in my opinion.
There is a lot of hype now for Rust. It is interesting. But I think perfecting oneself in C would achieve more than learning all the many concepts of Rust. But I see this more in solo programming. C may be hard to scale in large projects. I have difficulties to read through the linux kernel source code.
There is still a paradox. For very performance critical applications, companies will chose C++ over C because C++ is more safe. But in raw performance, it would go faster in C. If at wall street in the financial world, an application needs to calculate very quickly the stocks variations. ALl those layers I talked about take time. But they'd rather want the program to be correct than faster.