[vtk-developers] Use of assert

David Cole david.cole at kitware.com
Thu Jul 21 13:25:27 EDT 2005


Perhaps there should be a "VTK_ASSERT" wrapper that gets used within VTK 
proper...? That way we can control whether an abort happens or not, at 
least for the ones that are in VTK source.

Although, grepping on assert underneath VTK yields quite a large number 
of "assert" hits within the various utility libs : vtktiff and now the 
recently added vtknetcdf. So users of those may still be subject to the 
occasional abort...

It would be my expectation that an assert is usually a severe 
programming mistake, something "impossible," followed shortly by a crash 
of some sort.  A crash is preferable to an abort call nowadays with the 
"crash reporting" technologies on Windows and Mac.

For any end-user application (like ParaView) there ought to be no chance 
of an unexpected abort call - assert code should certainly be a no-op in 
a "Release" build...

An excellent treatment of this subject appears in the book Writing Solid 
Code, by Steve Maguire. I definitely recommend reading the section on 
"assert philosophy" in there.


Just my two cents,
David Cole


Mathieu Malaterre wrote:

>Ken,
>
>   Since I am responsible for most of the undocumented assert in the XML-IO stuff, here are my thoughts. According to Berk application like ParaView can be build in Debug mode (meaning with assert enable). He believes that ParaView should not ever abort on purpose. 
>
>   Most of the assert are checking that the inputs are correct for the functions. There are still some other assert that check nothing 'impossible' is happening. That was and still is pretty usefull for debuging. For instance I was not reinitializing the array when the user was reusing the same writer. The assert caught it right away, the bug was solved almost immediately.
>
>   Therefore the question is what should one do with those type of assert when something new is added to VTK and hasn't been tested for a long time ?
>
>   BTW what kind of user on purpose build ParaView in Debug mode ? What are your comment on the above, and on the fact that your application could abort ?
>
>Thanks,
>Mathieu
>
>  
>
>>Since I am seeing more use of assert in VTK, such as...
>>
>>    assert(numPieces > 0);
>>
>>is there a reason why we shouldn't require that people comment their assert
>>statements? For example the above assert should be 
>>
>>assert(numPieces > 0 && "OffsetGroupManager allocation requested for
>>numPieces <= 0")
>>
>>I think on most systems if the debugger is not invoked the content of the
>>assert will be displayed at least. Am I missing something?
>>
>>Thanks
>>Ken
>>
>>
>>_______________________________________________
>>vtk-developers mailing list
>>vtk-developers at vtk.org
>>http://www.vtk.org/mailman/listinfo/vtk-developers
>>
>>    
>>
>
>_______________________________________________
>vtk-developers mailing list
>vtk-developers at vtk.org
>http://www.vtk.org/mailman/listinfo/vtk-developers
>
>  
>



More information about the vtk-developers mailing list