Reply to post:

Email client lib blown apart by CC: list of death

the spectacularly refined chap

If it's C then things are not always that straightforward. No exception handling complicates how to indicate problems massively, particularly if the target domain of the result covers all values of the return type, and the function simply can't throw an error if its preconditions are satisfied. Constantly checking prerequisites introduces a lot of red tape which obscures the proper operation risking more bugs, and breaks a central principal of design by contract.

Put another way, in C for well written code this often becomes 1) check preconditions 2) call function via needlessly cumbersome invocation 3) function does it's own checks which can't fail due to the checks already done 4) caller now checks result which is also a waste of time because of those same initial checks.

Now for badly written code: what makes you think they'll bother with 4) after skipping step 1)?

By all means drop a few assert()s in there to catch problems in debug trim, they are nowhere near as intrusive and can greatly help self documentation. But adjusting things at the API level and repeatedly testing the same thing wastes time and space and risks introducing more problems by obscuring correct operation.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon