4 ms·
The last sentence doesn't really follow from the previous one. C++, like other higher level languages, has complexity built in because it takes care of things t
by wizofaus 4y ago
The last sentence doesn't really follow from the previous one. C++, like other higher level languages, has complexity built in because it takes care of things that in C you have to take care of yourself. I can't imagine any serious C++ project becoming "less complex" to work on by rewriting it in C.
- uecker 4y agoI personally found it very relieving when I switched from C++ to C. (and I also rewrote some stuff, it did not get more complex.) I find readability of modern C code much better than C++. In C you see what you get: no templates, overloading, virtual inheritance, namespaces, exceptions, references etc you need to keep processing in your head just to understand what is going on.
- wizofaus 4y agoI don't doubt that can be true - but there are plenty of common operations like concatenating strings or converting between strings/numbers that are a good deal simpler to write and understand in C++ than they are in C. In particular there are far more ways to get them wrong in C!
- uecker 4y agoIf you code them by hand, then yes. If you a library, then it is the same. It is certainly true that the C++ standard library provides more functionality out of the box.
- wizofaus 4y agoAlmost any C library function that deals with strings is going to be more complex to use due to the lack of automatic memory handling, necessary for any use case where the max. size isn't sufficiently well-known at compile time for it to sit on the stack. I'd accept something like "atoi" or "strtol" is pretty simple to use (and hard to get wrong), but hardly win any awards for obviousness. And the less said about the need (or at least strong tendency) to use sscanf for more complex parsing (hexadecimals etc.), the better.
- uecker 4y agoA library can do the memory management for you: string a = string("test"); string b = string(" this"); string n = string_concat(a, b); ...
- another2another 4y agoI started doing this a bit myself too, but soon found that I missed RAII too much. Having things clean themselves up when going out of scope is very convenient, and means that the early return code style that I favour is much easier to implement.
- MattPalmer1086 4y agoI'm talking about language complexity, not the complexity of code written in it. Sure, you have to do more for yourself in C, as it isn't as powerful as C++. C++ is the only language I've worked with where you have to tell people which bits of the language they can use!
- wizofaus 4y agoYour last sentence was that "there are fewer things you need to worry about in C". Which doesn't follow from c++ being a more complex/powerful language.
- MattPalmer1086 4y agoYes, it does although we seem to be coming at this from different perspectives. The C++ language spec is just vast. There are many footguns when doing apparently safe things. Different code bases use different subsets of the language. It is immensely powerful. C, by contrast, is just a much simpler language than C++. I'm not entirely sure what you are disagreeing with.