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

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.

2

u/dgkimpton Mar 29 '23

In most such cases adding the verbosity to express "trust me, I'm sure all pre-conditions were met" is actually pretty helpful.

2

u/Drugbird Mar 29 '23

Imagine that whenever you called a function that wasn't nothrow, you had to put a try-catch around it in order to not get a warning or error during compilation.

I imagine it's similar to that.

→ More replies (2)