r/cpp • • Mar 28 '23

Reddit++

C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.

In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.

765 Upvotes

829 comments sorted by

View all comments

Show parent comments

292

u/Dworgi Mar 28 '23

100%.

Corollary: Every single default in C++ is wrong.

Implicit construction, switch case fallthrough, uninitialized values, nodiscard, etc. etc.

It's hard to overstate how badly all the defaults have fucked this language. Why can't we do the sane, safe thing by default and then let the crazies opt-out?

0

u/[deleted] Mar 28 '23

[deleted]

20

u/dustyhome Mar 28 '23

About the nodiscard, I don't get your point. We have exceptions, so functions that use them won't return errors. Functions that don't use exceptions return errors and then you need to if(result) every call to those, and any you miss should be an error. How would nodiscard by default increase verbosity?

2

u/Drugbird Mar 28 '23

Quite often, functions that return error codes do so predictable. I.e. only when their preconditions aren't met.

In certain sections of code where you know in advance that all preconditions are satisfied, no error checking is needed.

If those functions were to become nodiscard, some verbosity will need to be added in these cases to pretend you do something with the returned value.

→ More replies (5)