Re: [Wikitech-l] Is assert() allowed?

2013-08-01 Thread Tim Starling
On 01/08/13 15:49, Tyler Romeo wrote: On Wed, Jul 31, 2013 at 10:47 PM, Tim Starling tstarl...@wikimedia.orgwrote: If the error is serious and unexpected, and likely to cause undesirable behaviour If this is the case, then you don't use assertions. You would use assertions for things

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Daniel Kinzler
My take on assertions, which I also tried to stick to in Wikibase, is as follows: * A failing assertion indicates a local error in the code or a bug in PHP; They should not be used to check preconditions or validate input. That's what InvalidArgumentException is for (and I wish type hints

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Christian Aistleitner
Hi Tyler, good to see that since the last discussion of this topic, more people are in favor of allowing asserts :-) On Tue, Jul 30, 2013 at 06:45:37PM -0400, Tyler Romeo wrote: I think the real issue here is just that assertions sometimes aren't used correctly. I wholeheartedly agree. Best

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Christian Aistleitner
Hi, On Wed, Jul 31, 2013 at 10:36:56AM +0200, Daniel Kinzler wrote: * Use boolean expressions in assertions, not strings. I do not agree that this is best practice in PHP. Execution time being only part of argument here. Among other arguments are readability of the error message. When using

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tim Starling
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

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tyler Romeo
On Wed, Jul 31, 2013 at 7:42 AM, Tim Starling tstarl...@wikimedia.orgwrote: 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. ...except PHP's assert() *also* aborts the program if enabled. What am I

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Happy Melon
$_GET[foo] = 'include( evil_file.php )'; assert( '$_GET[foo] == fluffy bunny rabbit' ); // This is fine assert( $_GET['foo'] == 'fluffy bunny rabbit' ); // But this is not Deliberately using a function which reduces the security of your application to relying on everyone choosing the correct type

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tyler Romeo
On Wed, Jul 31, 2013 at 8:38 AM, Happy Melon happy.melon.w...@gmail.comwrote: Deliberately using a function which reduces the security of your application to relying on everyone choosing the correct type of quotes is definitely asking for trouble. I don't see how this is an issue.

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Happy Melon
On 31 July 2013 15:01, Tyler Romeo tylerro...@gmail.com wrote: On Wed, Jul 31, 2013 at 8:38 AM, Happy Melon happy.melon.w...@gmail.com wrote: Deliberately using a function which reduces the security of your application to relying on everyone choosing the correct type of quotes is

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tyler Romeo
On Wed, Jul 31, 2013 at 10:24 AM, Happy Melon happy.melon.w...@gmail.comwrote: Yes, IMO, it should be abstracted away with a carefully-written wrapper function that bridges the semantic gap between I want to do some character conversions and I want to make this text safe to echo to the

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tim Starling
On 31/07/13 22:19, Tyler Romeo wrote: On Wed, Jul 31, 2013 at 7:42 AM, Tim Starling tstarl...@wikimedia.orgwrote: 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. ...except PHP's assert() *also*

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tyler Romeo
On Wed, Jul 31, 2013 at 7:28 PM, Tim Starling tstarl...@wikimedia.orgwrote: The php.ini option assert.bail is 0 by default. So? It's the same way in Java. You have to turn on assertions. It's kind of natural to assume that if assertions are off the won't cause fatal errors. *-- * *Tyler

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tim Starling
On 01/08/13 10:05, Tyler Romeo wrote: On Wed, Jul 31, 2013 at 7:28 PM, Tim Starling tstarl...@wikimedia.orgwrote: The php.ini option assert.bail is 0 by default. So? It's the same way in Java. You have to turn on assertions. It's kind of natural to assume that if assertions are off the

Re: [Wikitech-l] Is assert() allowed?

2013-07-31 Thread Tyler Romeo
On Wed, Jul 31, 2013 at 10:47 PM, Tim Starling tstarl...@wikimedia.orgwrote: If the error is serious and unexpected, and likely to cause undesirable behaviour If this is the case, then you don't use assertions. You would use assertions for things that don't have major side effects on the

[Wikitech-l] Is assert() allowed?

2013-07-30 Thread Max Semenik
I remeber we discussed using asserts and decided they're a bad idea for WMF-deployed code - yet I see Warning: assert() [a href='function.assert'function.assert/a]: Assertion failed in /usr/local/apache/common-local/php-1.22wmf12/extensions/WikibaseDataModel/DataModel/Claim/Claims.php on line

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Tyler Romeo
On Tue, Jul 30, 2013 at 5:28 PM, Max Semenik maxsem.w...@gmail.com wrote: Warning: assert() [a href='function.assert'function.assert/a]: Assertion failed in /usr/local/apache/common-local/php-1.22wmf12/extensions/WikibaseDataModel/DataModel/Claim/Claims.php on line 291 Is this on a

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Matthew Walker
As for whether MW should use assertions, I don't remember/wasn't there for the original discussion, so I can't comment on that, although personally I don't see how they're that bad an idea. I wasn't there either; but from my experience assertions are bad because you are using them to guard

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Tim Starling
On 31/07/13 07:28, Max Semenik wrote: I remeber we discussed using asserts and decided they're a bad idea for WMF-deployed code - yet I see Warning: assert() [a href='function.assert'function.assert/a]: Assertion failed in

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Tyler Romeo
I think the real issue here is just that assertions sometimes aren't used correctly. Assertions and exceptions are fundamentally different concepts. Assertions should be used for statements that literally should always be true. And I mean that almost mathematically, as in most assertions should

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Kevin Israel
On 07/30/2013 06:28 PM, Tim Starling wrote: On 31/07/13 07:28, Max Semenik wrote: I remeber we discussed using asserts and decided they're a bad idea for WMF-deployed code - yet I see Warning: assert() [a href='function.assert'function.assert/a]: Assertion failed in

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Tim Starling
On 31/07/13 08:45, Tyler Romeo wrote: Assertions and exceptions are fundamentally different concepts. Assertions should be used for statements that literally should always be true. And I mean that almost mathematically, as in most assertions should be able to be logically proven. This is why

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Tyler Romeo
On Tue, Jul 30, 2013 at 7:37 PM, Kevin Israel pleasest...@live.com wrote: As in: that function is just as evil as eval(), and the innocent looking assert( $_GET[id] 0 ); assert( $this-functionFromSuperclass() ); This is what I mean by misusing the assert function. Assert should

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Jeroen De Dauw
Hey, Assertions should be used for statements that literally should always be true. Indeed. This is the case for the assertion that is failing. Apparently there is a bug somewhere, and a lack of appropriate tests. But never mind that bug, we got a much more exciting flame war to keep going here

Re: [Wikitech-l] Is assert() allowed?

2013-07-30 Thread Tim Starling
On 31/07/13 09:46, Tyler Romeo wrote: Interesting concept. I think in C, they are most often used for validating function input, so obviously they can be hit. The Wikipedia articles [[Assertion (software development)]] and [[Precondition]] both mention this usage. Using assertions to