Jump to content
XCOMUFO & Xenocide

Why So Many Asserts


Judeau

Recommended Posts

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...