Judeau Posted December 25, 2005 Report Share Posted December 25, 2005 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? Link to comment Share on other sites More sharing options...
Serge Posted December 25, 2005 Report Share Posted December 25, 2005 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?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 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. Link to comment Share on other sites More sharing options...
Judeau Posted December 25, 2005 Author Report Share Posted December 25, 2005 i see, so basically you use them as error checking , to backtrace from that assert and see what could have gone wrongi assume stable builds don't have asserts for reducing of cpu Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now