I am finding that using assert(...) makes my code shorter and easier to read, as opposed to lengthy if..else.. blocks. However, are there good technical reasons not to use assert(...) in shipping code, when it does the same thing as testing a return value while using less code?
I am finding that using assert(…) makes my code shorter and easier to read,
Share
Having read this article I will share my beliefs about
assert:Yes it’s fine to use
assertwhen something absolutely should meet the condition you are asserting.Many languages allow you to raise custom errors when asserting, C not having “Exceptions” may produce errors that are a little harder to diagnose without directly looking at the source in question.