+1 to what Tim said. I effectively said as much about a week ago when this was brought up on IRC.
I'd also add that the behavior of assertions vary based on configuration, which is confusing at best. Unlike MWExceptions, which are all handled the same.
-Chad On Mar 18, 2012 6:10 PM, "Tim Starling" tstarling@wikimedia.org wrote:
On 18/03/12 20:37, Christian Aistleitner wrote:
Dear all,
should we allow using PHP's assert [1] in MediaWiki code?
It would allow us to formulate and automatically verify conditions about code, while at the same time providing readable documentation of code for free.
Possible, exemplary use cases would be:
- automatically verifyable documentation of code's intent
- guarding against logic pitfalls like forgetting to set a variable in all branches of switches, if/else cascades
- guarding against using uninitialized variables
What do you think?
We use exceptions for that.
P.S.: For typical MediaWiki use cases, PHP's assert is even faster than throwing exceptions behind 'if'-guards.
That's funny, for me "if" is about 10 times faster than assert() in the non-throwing case. Micro-optimisation in PHP usually revolves around minimising the number of function calls, since a function call is relatively complex and expensive compared to other opcodes.
-- Tim Starling
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l