From: Dan F. <dfr...@cs...> - 2004-06-02 02:15:09
|
Jim Cheetham wrote: > I might have the wrong idea, but why are there numerous 'assert' calls > in the code, in things like function getRevisionBefore($version) in > WikiDB.php? > > If I understand assert correctly, it throws an error if it's function > is not true ... ? All that happens in the wiki is an unsightly error > message (and no page template, etc) when it's triggered. I think this > one is triggered by (near)simultaneous edits, but they seem to work OK > when refreshing the page. > > If asserts are needed, can the user experience be improved somehow? Jim, assert()s are used to find programming errors. An assert() states what the programmer claims should be true for the code to run correctly. This is very useful, especially for large programs, programs written over time, and written by many different people. I highly encourage assert()s, even of "obvious" things (which turn out later not to be true!). This is distinguished from an error condition (e.g, invalid user input, running out of disk space, etc.) that might happen even in a correctly functioning program, which should be handled by non-assert code (like if-s). For more about PHP assert, see for example: http://www.sitepoint.com/article/1008 HOWEVER, you may not wish to see assert() output in your production system. If that's true, you can turn them off. See the "assert.active" setting of PHP. For example: http://www.sitepoint.com/article/bug-detection-php-assertions/3 Dan |