Re: RFC: Expectations
| From: | Joe Watkins | Date: | Tue, 22 Oct 2013 18:47:24 +0000 |
| Subject: | Re: RFC: Expectations | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69778@lists.php.net to get a copy of this message | ||
On 10/22/2013 07:32 PM, Patrick Schaaf wrote:
Am 22.10.2013 20:07 schrieb "Joe Watkins" <krakjoe@php.net>:We are going round in circles, discussing what assertion should be used for, again. Production code should _NOT_ have catch blocks everywhere to manage exceptions that will NEVER be thrown, obviously. assertion is a debug and development feature, if you take code to production that catches exceptions that your configuration does not allow to be thrown then that's pretty silly. assertion should be used during development, in development environments where it is enabled, by the time your code goes to production it should not suffer ExpectationExceptions and cannot anyway. I think this thread and the RFC now contains enough information regarding exceptions, it is now covered ground. Cheers JoeYou can catch exceptions, and log them. You can do that without impacting everything around you, you can do that,or whatever else you like. You can do that handling when you have only a few toplevel scripts, like when you have a setup with a small number of toplevel controllers and almost no CLI stuff around. But due to the scoped nature of try/catch you cannot reasonably / painlessly do that when you have 270 toplevel web and CLI entry points that then each need such a try/catch block. Also, there is the problem with catch (Exception) blocks, which you might easily dismiss as bad form, but which I'm sure are widespread in the field - I certainly know they are in our codebase... On the other hand, setup of an assertion-failed callback can easily go into an auto_prepend file, or into any other standard include (autoloader or something) you might have - exactly because it is something done on the global level instead of the scoped try/catch requirement. And IF you like the exception thing you can make that callback throw whatever you like - but you do not force that model on everybody. Furthermore such an assertion-failed callback has exactly the same change of looking at backtraces, so touting that as a singular feature of the exception approach is not valid. Finally, with the exception approach it is simply not true that it will completely go away in production - because these try/catch blocks will be present for any code that wants to handle the issue, and you cannot make those go away. I'm all for an assert alternative that works with expressions instead of eval, and that completely goes away in the opcode (cache) when disabled in production. best regards Patrick I was pretty explicit: used properly.