Debug code: assert or if-statement?

Started by
11 comments, last by Russell 19 years, 10 months ago
quote:Original post by antareus
The asserts are for conditions which should never arise, such as being passed a null pointer when the function then goes ahead and dereferences said pointer.


Depends on the level of the function. If it''s an API level function, I''d consider this an error and return a status (or throw something) to the caller.
Advertisement
asserts are mainly a debugging tool. If statements should be used for run-time checking (for example, to make sure that users didn''t enter a number that was out of bounds or an invalid string or whatnot).

Don''t use if statements for the sake of debugging.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

quote:Original post by Etnu
Don''t use if statements for the sake of debugging.


You can turn debugging information on and off at runtime if you use if statements.

This topic is closed to new replies.

Advertisement