The biggest take-away (for me) of the discussion is: Pros: - perf: zero-cost assertions Cons: - the benefits of zero-cost assertion is not worth the risk in a moving code-base like MW. The argument is that even in the case of assert being used properly (to expose strong expectations that cannot be unmet). Problems are too frequently found in production mode so benefiting from zero-cost assertions would be a risk in the sense that we would not be able to detect these errors.
On Thu, Mar 15, 2018 at 3:30 PM, Cormac Parle cparle@wikimedia.org wrote:
Was the conclusion “don’t use assert()”? It’s not really that clear to me
(fwiw I've always felt a bit squiffy about assert()s in production code, because it’s easy to make a php config mistake and get errors happening all over the place)
On 15 Mar 2018, at 14:17, David Causse dcausse@wikimedia.org wrote:
Replying to myself: I just found some discussions here: https://lists.gt.net/wiki/wikitech/378676 I bet that the new assert features in PHP7 don't change the conclusions here, so please ignore my e-mail and sorry for the noise.
On Thu, Mar 15, 2018 at 2:42 PM, David Causse dcausse@wikimedia.org
wrote:
Hi,
Sometimes I find adding assert() calls in my code very handy for various reasons:
- failures in development mode on some complex code where exposing all
the
details to unit tests is sometimes hard and/or pointless
- readability of the code
But I worry about the perf implications of these lines of code. I don't want these assertions to be used to track errors in production mode.
PHP7 introduced expectations which permit to have zero-cost assert() [1] Looking at the MW codebase we don't seem to use assert frequently (only
26
files [2] ).
Are there some discussions about this? Is assert() a good practice for the MW code base? If yes would it make sense to benefit from zero-cost assertions in WMF appservers?
Thanks!
[1] http://php.net/manual/en/function.assert.php#function. assert.expectations [2] https://codesearch.wmflabs.org/search/?q=%5Ctassert%5C(&
i=nope&files=
php%24&repos=
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l