Derek,

>From: [email protected] 
>[mailto:[email protected]] On Behalf Of Derek Foreman
>Sent: den 15 oktober 2015 19:22
>To: Andersson, Gunnar; [email protected]; [email protected]; 
>[email protected]; 
>[email protected]; Leon Anavi
>Subject: Re: Asserts? (was: RE: Keyboard issues with Weston and AGL 
>application suite)
>
>On 15/10/15 11:26 AM, Andersson, Gunnar wrote:
>> This is not really on topic...
>> 
>> But seeing this issue just reminds me of a question that nags me. 
>> 
>> Why do people not use asserts in most projects?   Is it considered 
>> to be ugly noise, is it not "cool" to use them, ... or what?
>> 
>> It's just that in a line like the original one (this is just an example)
>>    
>>    &context->input_method->seat->keyboard->input_method_grab;
>> 
>> at least my brain *cannot* avoid asking if every pointer is valid...
>> 
>> Is it just obviously assumed that of course no one has accidentally 
>> left a null or uninitialized pointer there or is it that most programmers
>> simply prefer to crash, debug, and then fix?   In other words assume
>> everything is alright until crash?  Maybe that is a worthwhile trade-off
>> I don't know - personally I prefer asserting.
>> 
>> Don't get me wrong, the bug fix you made is fine... but yet 
>> use of asserts might have reported the exact location of a bug
>> with what I would assume significantly reduced debugging time,
>> and the person asking the question may even be able to find it
>> himself?
>> 
>> So, opinion question... why do people not use asserts?   Is it not a 
>> worthwhile trade-off?
>> 
>
>There are well over 1000 assert()s between weston and wayland, so we're
>certainly not afraid of them.  (A quick grep shows 1400+ but some are in
>test cases...)

Glad to hear/see it.  I didn't grep because as I said it was not directed
at this project specifically.

>
>For that pointer string you selected, input_method->seat is initialized
>in text_backend_seat_creation() - if we have an input_method, it has a
>valid seat.
>
>seat->keyboard is only true if the seat has ever had a keyboard (it's
>actually nasty, and the reason why the current code accesses the
>keyboard through helper functions).  This was the source of the bug, and
>it's really unassertable outside of this function.  We can get there
>without a keyboard, and that's ok.  We just have to handle it when it
>happens.
>
>As to the rest, where would you put the asserts?  Just putting a stack

I don't know, it was an open question really.

>of asserts in that function seems pretty worthless since it's little
>more informative than a segfault.
>
>I fear the answer is frequently: The assert should go where you forgot
>to set the pointer properly in the first place.  Well, just setting the
>pointer there is really all that's required then.

True.  In some projects you probably have to assert way too much if it's
done in every function that uses the structure set up by someone else.

>
>For myself, I think I add more asserts for "boolean value isn't
>appropriate here" and "integer value is out of range" than I do for
>"pointer is NULL".

Makes sense.

>
>I just think it's harder to catch the "NULL pointer I'm not actually
>using in this function is going to bite me much later" case?
>
>All that said, if you want to add more asserts to weston and wayland,
>I'll gladly review any submissions, feel free to CC me directly and
>quote this e-mail. ;)

:-)  I'll do my best - quite many other things on my plate.  And although
we deal quite a lot with problems regarding wayland/weston I don't think
it's primarily due to general code quality, but honestly I don't know.

>
>I wouldn't mind seeing more asserts in weston at all, I think it'd
>improve at-a-glance readability in some cases, and it is supposed to be
>"reference" code...

Thanks for the feedback.

- Gunnar

>
>> Best Regards
>> - Gunnar
>> 
[trimmed]

_______________________________________________
Dev mailing list
[email protected]
https://lists.tizen.org/listinfo/dev

Reply via email to