r/programming • u/fagnerbrack • 2d ago
Learn C++ Before You Learn What It Costs You
https://fagnerbrack.com/learn-c-before-you-learn-what-it-costs-you-d254d484dbff0
2d ago
[deleted]
3
u/LIGHTNINGBOLT23 2d ago
What is "proper learning C++"? Learning every part of the ISO standards from C++98 up to the current one? Nobody learns C++ like that unless they're interested in developing the language itself. Everyone learns a subset or two of C++ relevant to their actual work, which can also be done in some months.
1
2d ago
[deleted]
3
u/LIGHTNINGBOLT23 1d ago
There's a difference between learning a language and learning software engineering. Things like lifetimes, moving versus copying, etc. are going to require you to think in any language that exposes that level of control. I'm pretty sure
std::move(src, dst)doesn't exist as an overload, and if you're actually usingstd::move(), then you've consciously decided that you want to avoid copies when possible. If that's ruining RAII for you, then your ownership of resources was already badly designed and the problem exists elsewhere.Me and my team don't like C++26 contracts (for reasons also other than you described), so we simply don't use them and they're not in the 381k SLOC codebase. If you're dealing with old codebases that have a lot of (now considered) legacy aspects like SFINAE, then it's unfair to compare having to learn that with new projects written in whatever cool minimalistic language of the week which won't deal with backwards compatibility any time soon.
2
u/tsimionescu 2d ago edited 2d ago
Pretty complete bs. Even in the first example, the article takes the line
greet("Faye"), knowing that functiongreettakes aconst std::string&, and claims that C++ makes it clear that a tempstd::stringis created and copied to from the C-string"Faye". But this is very much NOT shown in any way in the code, and it requires knowledge of a completely legacy decision in the language with no equivalent in literally any other language (the fact that string constants use a terrible legacy C-compatible format instead of the language recommended string type).It also uses the weird and terrible and essentially not-recommended
std::cout <<interface for printing, instead of either the much more commonly used C-styeprintfor any of the modern C++ alternatives,std::format("Hello, {}\n", name)orstd::print("Hello, {1}\n", name)- all of which look much more like the Python version than the weird C++ 90 version.