Hacker News new | ask | show | jobs
by deletes 4547 days ago
The point of assert is to check your code has values within your required parameters, so you the code is easier to debug while coding. Asserts should never be left in your code compiled for release. Even c library assert is aware of that, as it has the NDEBUG macro, which removes every assert in the code. That is also the reason why you should Never put code that might mutate your variables in them.( function calls or assigning, for example)

http://www.cplusplus.com/reference/cassert/assert/

Quote from the link: Therefore, this macro is designed to capture programming errors, not user or run-time errors, since it is generally disabled after a program exits its debugging phase.

Of course you can name your macro whatever you want, even assert, but it will confuse other developers used to c library functions.

1 comments

Fair enough -- assert was just the first name that came to mind. Perhaps something more descriptive like RETURN_ERROR_IF_FALSE would have been a better name.