5 ms·
Using std::vector, std::string and smart pointers would already bring large benfits, so even a C-like subset could work fine. The point is that code like in th
by blub 11y ago
Using std::vector, std::string and smart pointers would already bring large benfits, so even a C-like subset could work fine.
The point is that code like in that function is a nightmare to write correctly and test in plain C.
- pjmlp 11y agoI agree with you, the only problem being that even in 2016 there are shops that prohibit the usage of STL. The real way out is to eventually change to a language where safety is opt-out and not opt-in, like in C++.
- w8rbt 11y agoC++ is far safer than C precisely for the reasons listed. The standard is safe by default (it's not opt-in). If you want or need backward compatibility with C, then you can use the more error prone C constructs for that. Otherwise, pure C++ code is safe.
- pjmlp 11y agoIt is opt-in, because it depends on the STL, which many shops forbid. I have always been on the C++, in the C vs C++ wars, but I am also aware of all those developers that just code C with a C++ compiler, hence opt-in.
- ryandrake 11y agoI'd hope people are not using the STL nowadays, in favor of the C++ Standard Library which is part of the C++ standard.
- pjmlp 11y agoPeople like myself that know C++ since the "C++ Annotated Reference Manual" tend to keep using STL to designate the standard library, but I guess you already knew that. If it makes you happy I can use the ANSI C++ section number instead.
- ryandrake 11y agoWasn't sure if that's were you were going. So, who in this day and age, forbids the use of the standard library? That seems pretty bizarre. What would be the motivation behind such a policy?
- pjmlp 11y agoThe arguments against it are usually that it is too bloated, too slow, makes use of templates and exceptions. So any place that is against templates and exceptions, usually rules out the standard library on those arguments. Then you have the software houses, whose C++ code is actually C with a C++ compiler that use the bloat and slow arguments against the library. I don't remember them by heart, but there were a couple CppCon 2014 talks where this type of arguments was discussed.
- ryandrake 11y agoWhenever someone complains to me that the standard library is slow or "bloated" (whatever that means), I ask if they've ever profiled their code vs. the standard library version. 9 times out of 10 they have not, and are operating out of mythology rather than measurement.