2 ms·
Avoiding the newer parts is the worst imaginable response. If you write C code in C++, you will only have C code, and nothing better than C code. If you write
by ncmncm 5y ago
Avoiding the newer parts is the worst imaginable response.
If you write C code in C++, you will only have C code, and nothing better than C code. If you write Java code in C++ (which you can, and some do) you will only have Java code, and nothing better.
Leave the C parts behind. Leave the O-O parts behind. Lean into Modern C++, and reap the benefits of all the work put in to make the language better than C, better than Java (i.e. pre-C++98 plus GC), better than C++98, better than C++11, better than C++14, better than C++17.
Pointer arithmetic and inheritance are still occasionally useful; you can still wrestle in the mud. But if they show up in more than a few places in a program, you are Doing It Wrong.
- thesuperbigfrog 5y ago>> Lean into Modern C++, and reap the benefits of all the work put in to make the language better than C, better than Java (i.e. pre-C++98 plus GC), better than C++98, better than C++11, better than C++14, better than C++17. Serious questions: What subset of C++ is "Modern C++"? Are there flags for C++ compilers to only allow modern C++ and generate warnings when non-modern C++ is used? (For example, if an older-style C++ idiom is used, the compiler might say: "use of Old_Idiom is deprecated. Consider using New_Idiom instead".) I don't use much C++ and I have found the language daunting to learn because it is large, complex, and full of gotchas. A better subset that is enforced would help newcomers not get lost.
- ncmncm 5y agoThere are not such flags, but they would not be useful if there were. Real C++ programs link code of many different ages. Generally, you can only afford to make the new code, that you are writing now, the new way, and maybe modernize stuff immediately around it. The old stuff is typically well-exercised, and as long as it does its job you have no reason to touch it or, often, see it. But it is for the new code that the most value is available. Generally, if there are two ways to do something, and one appeared in a recent Standard, using that is usually the better choice. Cppreference.com helpfully tags each bit with when it appeared.
- gandvor 5y agoRegarding modern check flags: clang-tidy has its modernize-* flags
- systemvoltage 5y agoI’m not convinced about your counter argument, let alone worst imaginable response. All I’m saying is if a new feature is added to C++, it doesn’t affect me and I can choose to pick which features are useful. I can still keep it absolutely minimal. C with some useful libs, and occasional OOP. Why this is the worst possible answer? Obviously it works for me, it makes sense to me and it is perfectly logical in my view. Others have said the language bloat creates burden when you read other people’s code. That makes sense to me. Care to elaborate more? If you want to harshly criticize, it’s fine but you need to say a bit more so I can understand where you’re coming from. I just see a bunch of rhetorical statements.
- ncmncm 5y agoNothing is added to C++ without demonstrating usefulness. There is no "language bloat". If you fail to find any of it useful, it can only be by not paying attention. Yes, you can limit yourself to the C and Java subset, just as you can drive everywhere in first gear, can eat all your food raw, can crap in a hole. Just because you can does not make it a good idea. Objectively, the more your code looks like C, the worse it is, because you are inviting into it all of the flaws endemic to C code.
- dralley 5y ago>> Nothing is added to C++ without demonstrating usefulness. There is no "language bloat" "Bloat" doesn't require that the features are literally useless, merely that their usefulness doesn't justify their added complexity. And for many people, a huge portion of C++ falls into this category. Just look at the 18 different methods of initialization for an example of this. Or look at ranges, which seem to simultaneously be far more verbose than the alternatives in every other language, while having measurable negative impacts on compile times (that have spread throughout the stdlib, so even if you don't use them you have to pay for them). Ranges are certainly "useful" but the cost/benefit ratio is questionable.
- ncmncm 5y agoRanges had to be implemented without using the new language features that would make it easy and clean. Its authors had to use template-metaprogramming substitutes that are slow. As the language implementations catch up, the library can be upgraded and will get faster to compile. There are new initialization modes that are simpler. The old ones still have to work. But you don't have to use the old ones anymore.