Why So Many Asserts
Posted 25 December 2005 - 06:20 AM
Posted 25 December 2005 - 08:40 AM
Asserts are used as guard checks for the conditions that should be never false by design. If assert gets triggered, there is something wrong happening and it needs our close attention and special investigation. Using 'if' statements everywhere would just hide bugs and lead to unpredicted behaviour. Not to mention that writing error handler for the error that is 'theoretically impossible' to happen is a waste of time and addition of extra lines of code
why is the assert used so often in the code?, wouldn't using if statements that change the value that is being checked be more reliable?
Also when running on very slow hardware, compiling with -DNDEBUG would remove all the assert checks from the code completely and improve performance. But in beta builds more error checks are obviously more important than a very little performance gain.
But some asserts are inserted as placeholders for proper error handling when writing new code and when we don't know for sure in which conditions this error could arise and how we should handle it.
Posted 25 December 2005 - 12:07 PM
i assume stable builds don't have asserts for reducing of cpu