4 ms·
I write a lot of code in a C++ codebase and I'd say C++ is horrific. Not just because of its roots in C, no I think it is actually a worse language than C. Nota
by slaymaker1907 5y ago
I write a lot of code in a C++ codebase and I'd say C++ is horrific. Not just because of its roots in C, no I think it is actually a worse language than C. Notable detriments in the language include references, classes, a lot of template stuff (some of it is ok, but it makes separate compilation almost impossible).
- google234123 5y agoYour examples for why C++ is bad are references, classes, and templates? So I guess you like Fortran77?
- loup-vaillant 5y agoReferences are kind of redundant when you already have pointers, and they make the performance characteristic of the code you read less clear (am I passing down a pointer, or am I copying the whole thing?). C structs can already do most of what C++ classes can do. Including inheritance and virtual methods, when you really really need them. As for encapsulation, pointer to implementation provide a more stable, harder to cheat interface than private members. A must for stable ABIs. C does lack generics, and I do often miss them, but templates really aren't a good solution. I don't know what a good solution looks like, I haven't looked at Zig or Rust yet. Another thing I miss in C is a namespace system, especially when you ship libraries: makes every name longer, and you still have annoying name clashes from time to time.
- bitwize 5y ago> References are kind of redundant when you already have pointers, No. They're not. References must point to valid objects (i.e., cannot be nullptr and cannot be random addresses in memory), and you cannot do arithmetic on them. They are much safer to use than pointers, so actually, references make pointers redundant. > C structs can already do most of what C++ classes can do. Including inheritance and virtual methods, when you really really need them. Only much more cumbersomely.
- loup-vaillant 5y agoYes, references have nice constraints that makes them harder to misuse than pointers. The gap however is smaller than it first look: dangling references are still a thing, and one does not simply make pointer arithmetic by accident. Don't get me wrong, I do like references enough that my C++ code is littered with them. I'm just saying they don't add that much to the table. They're nice, but I never really miss them when I write C. Yes, writing your own virtual table in C is mighty cumbersome. On the other hand, I need those about once every 3 years, even in C++.
- bicolao 5y ago> one does not simply make pointer arithmetic by accident I'm not sure about that. This has bitten me a few times (in more complicated form) "hello " + 12
- gk1256 5y agoWhat's bad for him is good for me. Those C++ features helped me a lot. Actually, in terms of business value they saved me a lot of time.
- hobomatic 5y agoThe roots in c being a problem to me doesn't indicate the blame for them is necessarily inherited from c. The confusion about 'auto' elsewhere here is demonstrative. C++ is superficially similar to c in a lot of ways that don't actually translate well across the boundary between the two. So some c things get misattributed to c++ and many c++ things get misattributed to c and disentangling these is nearly impossible if you aren't intimately familiar with both of them. Being intimately familiar with either is a detriment to maintaining unmuddled working knowledge of the other.
- Koshkin 5y ago> detriments in the language include references, classes Maybe it's just me, but I can no longer live without those.