r/ProgrammerHumor • • 19d ago • Bravo 1

Meme poohWritesCpp

Post image
949 Upvotes

95 comments sorted by

View all comments

Show parent comment

64

u/Blue_Moon_Lake 19d ago

I'm pretty sure some of these are useless and should be deprecated.

105

u/SuitableDragonfly 19d ago

Does anything in C++ ever actually get deprecated?

53

u/Blue_Moon_Lake 19d ago

Sadly no, which is why it's a mess to figure out what you should avoid doing and what you should do.

Which is dumb, because you can deprecate something without removing it.

22

u/arachnidGrip 18d ago

`-Wdeprecated`

-3

u/Blue_Moon_Lake 18d ago

What?

9

u/Str1dersGonnaStride 18d ago

Pass the flag to tell the build tools to warn you about things that have been deprecated

8

u/a-r-c 18d ago

What?

i don't think that's a flag

21

u/SuitableDragonfly 19d ago

If you never actually remove the thing you deprecated, there isn't much point to deprecating it. 

21

u/Mateorabi 18d ago

To warn against using it because there’s a more modern idiomatic way of doing it. 

18

u/Blue_Moon_Lake 19d ago

The point is to easily spot what should never be used

5

u/brainpostman 18d ago

The point is usually backwards compatibility.

17

u/arachnidGrip 18d ago

C++ has deprecated many things over the years but you need to tell it to warn you about deprecated features.

4

u/conundorum 17d ago

Yes, actually. Mainly library members, though, it's rare that a language feature will be deprecated because they don't want to risk breaking very important 20-year-old unmaintained libraries that the entirety of modern infrastructure depends on. (It's a meme, but we meme about it because it's true.)

The most notable one is dynamic exception lists (throw(whatever) in the function signature), which got deprecated and mostly removed because nobody ever cared enough to actually support it. It was on life support for a while, where the "throws nothing" version (the only one that ended up being not worthless) is a synonym for noexcept, and every other throw-list is dead, before it got the boot too in C++20 or so. And similarly, the most notable library feature is probably "good" old std::auto_ptr, which got deprecated in C++11 because it was kinda really bad and unique_ptr was better, and finally got the boot in C++17.

Apart from that... it's hard to find a good list online, really. There's a partial list here, but you'd probably have to scour the various standards to find something more complete.


Now, that said, being deprecated (or even removed) doesn't mean that compiler vendors actually listen, because they're the ones that have to actually support all those ancient legacy codebases. Especially if the compiler includes version switches. If a compiler includes, e.g., both -std=c++11 and -std=c++17, then it will never remove features that were removed in C++17; it can disable them for -std=c++17 mode, but it still needs to be able to provide them for -std=c++11 mode.

So what it ultimately boils down to is that the language tries to deprecate & remove things, but legacy code is holding the compilers hostage.

3

u/AvidCoco 18d ago

Any good linter will warn about using dumb ones

4

u/Blue_Moon_Lake 18d ago

And how would someone inexperienced know if they're using a GOOD linter?

2

u/AvidCoco 18d ago

They’d google it?

2

u/Athropod101 17d ago

And they’ll find a bunch of linters, because C++’s toolchain ecosystem is amazing 😃

3

u/conundorum 17d ago

Eh... not really, weirdly enough. Some of them are just the same thing in different places and/or contexts (e.g., "copy initialisation", "constant initialisation", "initialisation with auto", "in-class member initialisers" & "constructor member initialiser list", and "if/switch init-statements" are all the same feature in different contexts), and most of the others do different things under the hood (e.g., constructor delegation allows you to chain constructors, default initialisation lets you use the type's base rules, copy initialisation duplicates another object (or is optimised into direct optimisation if possible), direct initialisation hard-codes into the executable, zero initialisation sanitises memory, reference initialisation is singled out because it either registers a second name or creates a pointer, etc..).

It's a case where the language makes it look more complex than it actually is... which, admittedly, happens a lot in C++. Most of these really just boil down to "how Type t = val; works depends on what Type is", more than anything else.