A coworker has added the assert command a few times within our libraries in places where I would have used an if statement and thrown an exception. (I had never even heard o
Think of asserts as "power comments". Rather than a comment like:
// Note to developers: the parameter "a" should always be a number!!!
use:
assert('is_numeric(a) /* The parameter "a" should always be a number. */');
The meanings are exactly the same and are intended for the exact same audience, but the first comment is easily forgotten or ignored (no matter how many exclamation marks), while the "power comment" is not only available for humans to read and understand, it is also constantly machine-tested during development, and won't be ignored if you set up good assert handling in code and in work habits.
Seen this way, asserts are a completely different concept than if(error)... and exceptions, and they can co-exist.
Yes, you should be commenting your code, and yes, you should be using "power comments" (asserts) whenever possible.