Hacker News new | ask | show | jobs
by theseoafs 4555 days ago
To be fair, I don't see why you would have to throw your keyboard out the window. If I were debugging a source file and saw the same ASSERT macro on every other line, I would break out `grep` and track down the (extremely simple) definition so I could understand what it's doing. Moreover, returning with an error code is IMO entirely sane behavior for a macro with ASSERT in the name, especially considering halting execution of the program altogether generally isn't a good thing if you're writing a C library.
1 comments

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.

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.