From: Jim C. <ji...@in...> - 2004-06-01 21:18:57
|
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 |
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 |
From: Reini U. <ru...@x-...> - 2004-06-02 08:34:02
|
Dan Frankowski schrieb: > 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. I added now the logic to assert only if DEBUG is non-false. If you want to assert always (which is recommended) you have to put comments before the two lines in lib/ErrorManager.php: if (DEBUG) assert_options (ASSERT_ACTIVE, 1); else assert_options (ASSERT_ACTIVE, 0); -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban/ |
From: Dan F. <dfr...@cs...> - 2004-06-02 16:49:10
|
You didn't cc the list, so I do. Jim Cheetham wrote: > Thanks to both Dan and Frederik for confirming my thoughts about > assert(), and expanding on them :-) > > With respect to turning these off in production, my question becomes :- > > Should phpwiki have active assert statements for production users? Can > we turn them off with the equivalent of DEBUG = 0, or via .htaccess > setting a php value? Reini changed this in CVS so DEBUG=0 turns off assert()s. > and > > Given that I've seen WikiDB getRevisionBefore($version) throw out an > assert when submitting a page edit (on a dba=file wiki), does that > indicate a problem that needs to be fixed, either in phpwiki or on my > site? Yes. Either in the code or in the assert. Dan |
From: Reini U. <ru...@x-...> - 2004-06-02 17:14:00
|
Dan Frankowski schrieb: > You didn't cc the list, so I do. > Jim Cheetham wrote: >> Thanks to both Dan and Frederik for confirming my thoughts about >> assert(), and expanding on them :-) >> >> With respect to turning these off in production, my question becomes :- >> >> Should phpwiki have active assert statements for production users? Can >> we turn them off with the equivalent of DEBUG = 0, or via .htaccess >> setting a php value? > > Reini changed this in CVS so DEBUG=0 turns off assert()s. > >> and >> >> Given that I've seen WikiDB getRevisionBefore($version) throw out an >> assert when submitting a page edit (on a dba=file wiki), does that >> indicate a problem that needs to be fixed, either in phpwiki or on my >> site? Which phpwiki version? Thanks for the report. But I think found the error, which is fixed in current CVS. $backend->get_previous_version() returns false instead of 0, which hurts getRevisionBefore(). > Yes. Either in the code or in the assert. For sure in phpwiki. asserts are so simple that they cannot be wrong. -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban/ |
From: Jim C. <ji...@iN...> - 2004-06-02 20:49:08
|
Reini Urban wrote: > Dan Frankowski schrieb: >> You didn't cc the list, so I do. Thanks Dan, you're right, I forgot to send to the list :-( > Which phpwiki version? Thanks for the report. 1.3.9 > > But I think found the error, which is fixed in current CVS. > $backend->get_previous_version() returns false instead of 0, which hurts > getRevisionBefore(). Excellent work, thanks for that :-) -jim |
From: Frederik De B. <fre...@pa...> - 2004-06-03 11:23:47
|
I forgot to CC the list as well, so here's my description of "assert": > 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? I'm quoting from the "Programming With Assertions" introduction here: An assertion is a statement that enables you to test your assumptions about your program. For example, if you write a method that calculates the speed of a particle, you might assert that the calculated speed is less than the speed of light. Each assertion contains a boolean expression that you believe will be true when the assertion executes. If it is not true, the system will throw an error. By verifying that the boolean expression is indeed true, the assertion confirms your assumptions about the behavior of your program, increasing your confidence that the program is free of errors. Experience has shown that writing assertions while programming is one of the quickest and most effective ways to detect and correct bugs. As an added benefit, assertions serve to document the inner workings of your program, enhancing maintainability. > All that happens in the wiki is an unsightly error message (and no page template, etc) when it's triggered. Assertions should look like big red warning signs to remind the programmer that something is very wrong. And again, they're not something the client will ever see. A good read is "bug detection with PHP assertions". This article also mentions how to turn off assertions for production code, so that the user doesn't get to see the result of an assertion. Even better, the evaluation of assertions can be turned off completely, improving the speed of your application (although marginally). http://www.sitepoint.com/article.php/1008 Frederik P.S. The mentioned article, Programming with Assertions, can be found here: http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html |