debugcppCritical
Is assert evil?
Viewed 0 times
evilassertstackoverflow
Problem
The
Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue operation after non-fatal errors instead of crashing. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.
How would these arguments apply to C or C++? What are some pros and cons of using
Go language creators write:Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue operation after non-fatal errors instead of crashing. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.
How would these arguments apply to C or C++? What are some pros and cons of using
assert()?Solution
No, there's nothing wrong with
That is, it's supposed to be for catching cases that "can't happen", during debugging, as opposed to normal error handling.
assert as long as you use it as intended.That is, it's supposed to be for catching cases that "can't happen", during debugging, as opposed to normal error handling.
- Assert: A failure in the program's logic itself.
- Error Handling: An erroneous input or system state not due to a bug in the program.
Context
Stack Overflow Q#1854302, score: 328
Revisions (0)
No revisions yet.