5 ms·
Yeah as someone who writes C in C++, everytime I see posts bending over backwards trying to fit parameterized types into C I just cringe a little. I understand
by pton_xd 1y ago
Yeah as someone who writes C in C++, everytime I see posts bending over backwards trying to fit parameterized types into C I just cringe a little. I understand the appeal of sticking to pure C, but... why do that to yourself? Come on over, we've got lambdas, and operator overloading for those special circumstances... the water's fine!
- pjmlp 1y agoSome people will do as much as they can to hurt themselves, only to avoid using C++. Note as the newer versions are basically C++ without Classes kind of thing.
- glouwbug 1y agoI think the main appeal is subset lock-down and compile times. ~5000 lines in C gets me sub second iteration times, while ~5000 lines in C++ hits the 10 second mark. Including both iostream and format in C++ gets any project up into the ~1.5 second mark which kills my iteration interests. Second to that I'd say the appeal is just watching something you've known for a long time grow slowly and steadily.
- kilpikaarna 1y agoThis, and the two pages of incomprehensible compiler spam you get when you make a typo in C++.
- pjmlp 1y agoDepends pretty much on where you do such typo. If you mean templates, a kind of solved problem since C++17 with static_assert and enable_if, moreso in C++20 with concepts.
- pjmlp 1y agoUse binary libraries and modules, alongside incremental compilation and linking.
- uecker 1y agoI see it the other way round. People hurt themselves by using C++. C++ fans will never understand it, but it you can solve your problem in a much simpler way, this is far better.
- TuxSH 1y agoIMHO C++ scales far better for large, self-contained, personal projects though it requires slightly more initial investment. And if you're targeting PC, you might be better off using Python to begin with (if perf is not a concern)
- uecker 1y agoWhat specifically makes it scale better in your opinion?
- TuxSH 1y ago- "All" C libraries use some form of namespacing (the typical mylib_dosomething kind of name); actual namespaces mean you don't write these prefixes over and over again when in the same namespace - "Most" C projects do basic OOP, many C projects even do inheritance via composition and a fair few of these do virtual dispatch too - Templates (esp. since C++20), lambda functions, overloads and more recently coroutines (which are fancy FSM in their impl), etc. reduce boilerplate a lot - Containers (whether std:: or one's own) are far easier to work with in C++, a lot less boilerplate overall (GDB leveraged this during their migration iirc) - string_view makes non-destructive substring manipulation a lot easier; chrono literals (in application code) make working with durations a lot more readable too In the past decade or two, major projects like GCC and GDB have migrated from C to C++. Obviously, C retains advantages over C++, but they are fairly limited: faster build times, not having to worry about exposing "extern C" interface in libraries, not having to worry about controversial features like exceptions and (contextually) magic statics and so on...
- rramadass 1y agoNicely said! One other key thing is encapsulation provided via various C++ syntax which is missing in C (where only file scope is possible).
- spc476 1y agoSo maybe you can answer the following question I have: what is a "protected abstract virtual base pure virtual private destructor," and when was the last time you needed one?" At least with C, I understand the feature set and how they interact.
- jjmarr 1y agoDon't use inheritance and you won't have to find out.
- rramadass 1y agoThis is just silly. C++ gives you a smorgasbord of multi-paradigm features. Everything has its place and you can mix and match your needed featureset based on project needs, team skillset etc. You don't have to know or learn everything.
- pjmlp 1y agoJust because a feature is there doesn't mean you have to use it. Additionally the example isn't even possible, at least make ridiculous examples that compile.