by interestingcpp · 9y ago · 0 comments
Some of the complexity of C++ comes from it doing hard things, some is in part a consequence of heroic efforts at backwards compatibility. There are areas of the language that most people stay away from or use in very constrained ways like multiple inheritance that are unlikely to be deprecated for backwards compatibility reasons but in my many years of professional C++ development multiple inheritance has never caused practical difficulties for me precisely because everybody stays away from it except for pure abstract interfaces.
Instead, they add new features that lets new code be written in new ways without requiring you to toss out your old code. Your old C code is full of mallocs and frees. Your old code still works when you partially update it using the newest features. But, once C++ added new and delete, you rarely ever needed to type malloc or free any more unless you were overloading new and delete. Your old C++ code is full of news and deletes, but new language features added in C++11 made unique_ptr and shared_ptr possible. And, now you rarely need to type new or delete unless you are making your own unique_ptr/shared_ptr variant.
I am by no means arguing that C++ committees are making any mistakes.
why should it ? Adding features is enough for simplifying stuff.
eg take the following code:
for(auto& val : {1,3,12,17,20}) { val++; }
it leverages three new features: auto, range-based for, and braced initialization.How would it look in cpp03 ? Two possibilities:
std::vector<int> v;
v.push_back(1); v.push_back(3); ... v.push_back(20);
for(std::vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
(*it)++;
}
Or int v[] = {1,3,12,17,20};
for(int i = 0; i < (int)(sizeof(v)/sizeof(int)); i++) {
v[i]++;
}