When interfacing with other systems, you often do not know the whole value range of data in advance, or even what to do with a certain data value. Assertions help during development in such cases, as you can easily leave an assertion in places you are uncertain of, and come back later after your program crashed to examine the unexpected values.
>>6
That's exactly what contracts are for, really. Assertions are a basic way to check contracts, except that contract violations (with some language support) can be detected at compile time (to certain extent), false assertions can't (not as easily).
Name:
Anonymous2011-08-16 11:55
The practice of assert()ing things come mostly from C. As I personally stated elsewhere (thread already dead), C is a brain-crippled language. Don't use it: they tend to persist and create bad habits. In C, you ought to preprocess with NDEBUG if you do use, but no one really compiles with that definition.
There are languages which create more interesting assertion mechanisms (throwing an exception for example). These are much saner and safe to use, maybe even in production code.
In certain imperative programming languages, some weenie programmers will do some creative abuses with assertions, and like, use them to emulate certain boolean operations.
>>8 In C, you ought to preprocess with NDEBUG if you do use, but no one really compiles with that definition.
I don't think you know shit about C and its usage patterns, good sir.