Re: binary search with reference to append

new topic     » goto parent     » topic index » view thread      » older message » newer message
gimlet said...

You say the caller should validate.
Yet you still insist on bsearch rejecting invalid inputs.
Surely all bsearch needs to do is return correct results for
valid input.

I agree that the caller should be responsible for checking the data for validity, which is why I wrote the function to crash on bad input instead of silently continuing.

The reason for that is that when you write your first rough draft, it is easy to miss such conditions. Therefore the check in the callee is an aid to debugging -- when it crashes then it says to the programmer that there is a logic error upstream. We don't want a logic error to put our program or our output data into an unknown state with a bug which could turn intermittent and/or very difficult to track down otherwise.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu