How do you test pre-/post-conditions and invariants?

David Nadlinger see at klickverbot.at
Sat Feb 26 08:23:41 PST 2011


On 2/26/11 4:08 PM, Magnus Lie Hetland wrote:
> On 2011-02-26 15:20:19 +0100, David Nadlinger said:
>
>> On 2/26/11 1:15 PM, Jonathan M Davis wrote:
>>> [...] And from a perfectly practical standpoint, as soon as your code
>>> ends
>>> up in a library, assertions are generally useless anyway,[...]
>>
>> I don't quite think asserts are useless in libraries. If you need to
>> care about performance in a library, you hit cases quite frequently
>> where sanity-checking the input would be too expensive to be done in
>> release mode, and thus you can't specify behavior on invalid input as
>> part of your API using exceptions. Nevertheless, it is still useful to
>> people using your library to get notified when they are messing
>> something up as early as possible in debug mode, which is precisely
>> what asserts are made for, at least in my opinion.
>
> But that would only work if they had access to the source, or a version
> not compiled in release mode, right?

True, but as shipping debug libraries and headers is precisely what SDKs 
are for, I don't see much of a problem there. Heck, even Microsoft's C 
Runtime comes with an extra debug version…

David


More information about the Digitalmars-d-learn mailing list