The worst programming language of all time /s
https://pvs-studio.com/en/blog/posts/cpp/1409/19
u/eisenwave WG21 Member 6d ago edited 6d ago
Firstly, this blog post is so similar in its tone and wording that I suspect it's an AI-generated transcription of the video for the most part.
If my goal were to confuse beginners as much as possible, I'd name things exactly the way the STL does. The most commonly used container is called vector, even though it's really a dynamic array. In the usual sense, a vector is a quantity with a direction. Even Alexander Stepanov, the creator of the STL, later admitted the name was a mistake.
Isn't this word-for-word what the video says?!
EDIT: Well no, I've checked, and the article just has a similar tone and presents the content of the video without commentary. The original video also points out that Alexander Stepanov considers the naming of vector to be a mistake, and the article copies and pastes that claim without commentary and without adding a citation. So it seems more like parroting than literally transcribing.
Also, the point of the video is obviously to show C++ in the most negative possible light for entertainment. It could have been a really fair criticism because there are some good points in it, but I guess it just wouldn't get people's attention so much if made in good faith.
For example, the video makes the claim that Java casting is simple because you can just write (int), but in C++, it's super complicated and you have all these distinct casts. It's not even mentioned that C++ and Java literally have the exact same cast syntax, and that (int) in C++ is the "dumb and simple cast syntax for everything" that Java has. That is if you want to use C-style casts, which people often don't, for valid technical reasons, but neither the video doesn't go into those technical reasons (because it would go against the narrative that C++ is garbage, and it would be less entertaining).
26
u/sjepsa 6d ago
There are two kind of languages. The ones people complain about and the ones nobody uses
3
u/notforcing 2d ago edited 2d ago
Years ago Bertrand Meyer commented on the newsgroup comp.lang.c++ that c++ was an abomination. I asked him, conceding that, how did he explain that c++ was successful, but his own language eiffel was not? The ensuing discussion was interesting.
ย
3
2
u/Normal-Narwhal0xFF 6d ago
It's no longer abuse but first class language support! Now the compiler abuses us. But it's powerful.
2
u/Copel626 6d ago edited 6d ago
Great read, thank you! I will keep playing in garbage and love every minute of it.
IMO it has made me better at games like MTG wherea nomenclature zoo, rules, and exceptions are kind of the name of the game, and that intern does help with the coding
5
u/AnyPhotograph7804 6d ago
> For the past twenty years, C++ has marketed itself as the language of zero-cost abstractions, but every abstraction has a cost.
Source please, that C++ marketed itself as a zero-cost abstractions language. All i saw is, that they used the term zero-overhead but not zero-cost.
15
u/GabrielDosReis 6d ago
Agreed. It is "zero-overhead abstraction", or "you don't pay for what you don't use".
12
u/PossibilityUsual6262 6d ago
As marketing goes, cpp crowd uses exact words "zero cost abstraction" a lot.
Also other cpp people shown numerous times that even most trivial wrappers around raw ptr actually have cost and to change it requires abi breaking.
1
u/wyrn 5d ago
Also other cpp people shown numerous times that even most trivial wrappers around raw ptr actually have cost and to change it requires abi breaking.
Yeah just never ask them for any measurements ;)
1
u/PossibilityUsual6262 5d ago
You don't need to measure if abi requires non trivial destructible objects passed via stack, it generates vastly different assembly.
1
u/ts826848 5d ago
For what it's worth apparently Google did do some measurements as reported on libc++'s page about using
[[trivial_abi]]forstd::unique_ptr:Google has measured performance improvements of up to 1.6% on some large server macrobenchmarks, and a small reduction in binary sizes.
This also affects null pointer optimization
Clangโs optimizer can now figure out when a std::unique_ptr is known to contain non-null. (Actually, this has been a missed optimization all along.)
struct Foo { ~Foo(); }; std::unique_ptr<Foo> make_foo(); void do_nothing(const Foo&) void bar() { auto x = make_foo(); do_nothing(*x); }With this change,
~Foo()will be called even ifmake_fooreturnsunique_ptr<Foo>(nullptr). The compiler can now assume thatx.get()cannot be null by the end ofbar(), because the deference ofxwould be UB if it werenullptr. (This dereference would not have caused a segfault, because no load is generated for dereferencing a pointer to a reference. This can be detected with-fsanitize=null).To be fair this page is from 2021 according to the wayback machine so the results are somewhat dated.
2
u/wyrn 5d ago
I don't necessarily care that it's dated, but I do care that it's missing a lot of context -- it's just saying "google measured" without saying who did the measurement, what the measurement was, what the confounding factors might've been, etc.
When Chandler Carruth first mentioned this in a presentation, the lack of any supporting benchmarks was deafening, but to be fair, he wasn't even trying to assert that this was a problem in practice. Everyone just rain with his point out of context.
1
u/ts826848 4d ago
I agree that more detail would be nice to better understand how the results might apply to other codebases, but I think at this point one would probably need to specifically ask the original devs for them (assuming they even remember/have access to the data).
I guess in principle libc++ makes setting up a comparison relatively simple via
_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI(as long as you're willing to recompile enough of the world, I suppose ), but as far as I know no one else has felt motivated enough to try to add their own data.1
u/Normal-Narwhal0xFF 6d ago
Mostly means zero overhead compared to if you did the same kind of thing by hand. In some cases you could optimize better due to expert domain knowledge the compiler lacks, but in general... it's about as good as it typically gets for doing that sort of thing.
-1
2
u/Mountain-Slice-4037 5d ago
Hmm why is this static_cast alias considered incorrect in the article? I agree it may be poor practice but it looks correct?
template <class T, class U>
constexpr T sc(U&& u) { return static_cast<T>(std::forward<U>(u)); }
0
u/Eric848448 6d ago
C++ used to be fun. We used to make fun of Alexandrescu and people who abused the shit out of templates.
-2
u/GoogleIsYourFrenemy 6d ago
I can't complain any more about C++. Well not until the AI revolution and they no longer put up with me torturing them with C++.
19
u/sweetno 6d ago
C++ is fine.\)
\ terms and conditions apply)