On 31/07/13 18:36, Daniel Kinzler wrote:
> Assertions are things that should *always* be true.
> In my mind, assertions should just throw an (usually unhandled)
> exception, like Java's AssertionError.
Indeed. In C, assert() will abort the program if it is enabled, which
is hard to miss. It is not comparable to the PHP assert() function.
> I don't really see how the resulting boiler plate would be cleaner
> or safer:
>
> if ( $foo > $bar ) { throw new OMGWTFError(); }
The reasons I don't like assert() are:
1. It doesn't throw an exception
2. It acts like eval()
We could have a library of PHPUnit-style assertion functions which
throw exceptions and don't act like eval(), I would be fine with that.
Maybe MWAssert::greaterThan( $foo, $bar ) or something.
-- Tim Starling
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l