6 ms·
C with classes is peak C for me. C++ is best when it is fixing C, not when it tries to be something else entirely.
by kajaktum 3y ago
C with classes is peak C for me. C++ is best when it is fixing C, not when it tries to be something else entirely.
- rlawson 3y ago100% agree!
- uecker 3y agoC is peak C for me. I think you can better modularize in C than in C++ because with APIs build around incomplete struct types the implementation stays in the C file and does not leak into the header as with classes.
- sevagh 3y agoThe last I checked in C++, you need to use the PIMPL (private implementation) idiom for that behavior: https://en.cppreference.com/w/cpp/language/pimpl https://en.cppreference.com/w/cpp/language/pimpl (not my favorite)
- uecker 3y agoThe C header interface is simple: struct foo; struct foo *foo_alloc(); void foo_do_something(struct foo *p, ...); This gives a simple to understand API with clearly defined boundary, has a stable ABI, preserves fast compilation times, avoids instruction bloat, etc. One could do this in C++ too, but what would be the point of using C++ then...
- angiosperm 3y agoYou can use incomplete struct types in C++ as easily as in C. If you are hiding implementation, the struct will likely have a single data member struct private_impl_type; std::unique_ptr<private_impl_type> impl; If you choose this, you trade off optimization opportunities. Your choice.
- senderista 3y agoFor me the only truly compelling C++ features are RAII and generics (not classes or virtual functions), and those are compelling enough for me to not consider C when I can choose C++. From what I can tell, the Rust designers seem to have felt the same way.
- deleted 3y ago[deleted]
- angiosperm 3y ago"C with classes" is a recipe for bugs and unpleasant coding. Lean into modern C++, and your correct, performant code comes easily.