[openbeos] Re: Asserts?

  • From: "Michael Phipps" <mphipps1@xxxxxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sat, 05 Oct 2002 11:55:05 -0400

>Honestly, I'd be fa-bleeping pezzed off if a library were to assert, 
>throw, or whatever condition that would cause an unexpected termination 
>out of my control.  My long-standing rule is that there should *never* 
>be an exit from a library, period.  I wasn't sure of OBOS' standing on 
>the issue, this is why I chose to ping the group.

!!! Such strong language!!! ;-)

>> Asserts are really primitive exceptions for C.
>I disagree, setjmp/longjmp is C's version of exception handling both in 
>behavior and use.

Yes, more properly so. Certainly in terms of unwinding the stack and "stuff".
I was thinking more socially than technically. What? Social C constructs?
Yes, in terms of how people (or at least I) tend to use them. I rarely 
use exceptions for anything other than "this terminal, weird, messed up 
case just occured and it is time to pack it up and go home". The same way that
I tend to use assertions. I don't think that I ever used *jmp; they just seem 
like bad
news, to me. ;-)

>> Assertions
>> should be reserved for "I am internally screwed up in some way".
>That's different from my vision of asserts.  My vision of the purpose 
>of an assert is to trap errors during debugging cycles, before a 
>program is considered for 'release' status.  I tend to think of asserts 
>as a tool to trap stupid programmer errors.  For example, pointer 
>parameters being NULL when we expect them not to be, getting a divisor 
>that's zero, ad nauseum.

I think that we agree here, more than you think. Certainly asserts are for 
debugging cycles. :-) I was thinking of my linked list example - I am screwed
up because of stupid programmer errors. Absolutely, asserts catch
programmer errors - they are for error checking that, in a perfect world, would 
be part of the code, but should never be necessary and would slow the code down.

>To me, "I am internally screwed up in some way" is the perfect time to 
>throw an exception, not assert.

Depends on the source. What I had in mind was an object that has reached a
state that is supposedly unreachable because of some bug.

>Not trying to be confrontational, just engaging in lively discussion 
>with some of my peers.  :-)

I love it!

Other related posts: