[VOTE] Expectations

php.internals

Joe Watkins

11 years ago
Morning internals, The expectations RFC is now in voting phase: https://wiki.php.net/rfc/expectations#vote Cheers Joe

Markus Fischer

11 years ago
Hi, On 19.02.15 10:09, Joe Watkins wrote:
> Morning internals, > > The expectations RFC is now in voting phase: > https://wiki.php.net/rfc/expectations#vote
- I somehow miss information what the exact differences are to the current implementation, to better judge the impact. - how does zend.assertions and assert.exceptions work with "assert_options()" , i.e. isn't the exception behavior meant to be an addition to assert_options() too ? - the RFC says: "enabled (zend.assertions=1) on development machines, and disabled (zend.assertions=0) in production"; a few paragraphs above it says "-1 - don't generate any code (zero-cost, production mode)". Shouldn't be -1 the default value for production then? - the RFC says: "A call to assert(), without a fully qualified namespace will call assert in the current namespace, if the function exists. An unqualified call to assert is subject to the same optimization configured by zend.assertions. ". Does this mean I can control whether a function in a namespace is being optimized-away with when zend.assertion equals -1 and otherwise do my own stuff in there and need to raise an AssertException on my own to signal assertion fails? thank you, - Markus

Dmitry Stogov

11 years ago
On Thu, Feb 19, 2015 at 5:47 PM, Markus Fischer <markus@fischer.name> wrote:
> Hi, > > On 19.02.15 10:09, Joe Watkins wrote: > > Morning internals, > > > > The expectations RFC is now in voting phase: > > https://wiki.php.net/rfc/expectations#vote > > - I somehow miss information what the exact differences are to the > current implementation, to better judge the impact. >
The implementation introduces ZEND_ASSERT_CHECK instruction that will jump around calls to assert() depending on zend.assertions ini option. (call and constraint evaluation may be expensive). It's also possible to avoid compilation of asset() at all (setting zend.assertions=-1) This will allow using assert() for program testing, without performance degradation in production.
> > - how does zend.assertions and assert.exceptions work with > "assert_options()" , i.e. isn't the exception behavior meant to be an > addition to assert_options() too ? >
zend.assertions control assert() compilation and execution zend.assertions=-1 zero-cost, assert() won't be compiled at all (including inner code) zend.assertions=0 low-cost, assert() will be compiled but won't be executes (including inner code) zend.assertions=1 assert() wiil be compiled and executed as now
> - the RFC says: "enabled (zend.assertions=1) on development machines, > and disabled (zend.assertions=0) in production"; a few paragraphs above > it says "-1 - don't generate any code (zero-cost, production mode)". > Shouldn't be -1 the default value for production then? >
With zend.assertions=0 in production, you'll able to switch to zend.assertions=0 at any time. With zend.assertions=-1 of course not.
> - the RFC says: "A call to assert(), without a fully qualified namespace > will call assert in the current namespace, if the function exists. An > unqualified call to assert is subject to the same optimization > configured by zend.assertions. ". Does this mean I can control whether a > function in a namespace is being optimized-away with when zend.assertion > equals -1 and otherwise do my own stuff in there and need to raise an > AssertException on my own to signal assertion fails? >
Yes. you are able to eliminate your own assert() functions in namespaces. Thanks. Dmitry.

Markus Fischer

11 years ago
On 19.02.15 16:23, Dmitry Stogov wrote:
>> >> - how does zend.assertions and assert.exceptions work with >> "assert_options()" , i.e. isn't the exception behavior meant to be an >> addition to assert_options() too ? >> > > zend.assertions control assert() compilation and execution > > zend.assertions=-1 zero-cost, assert() won't be compiled at all (including > inner code) > zend.assertions=0 low-cost, assert() will be compiled but won't be > executes (including inner code) > zend.assertions=1 assert() wiil be compiled and executed as now
Pardon me, but it doesn't explain what the role of the existing "assert_options()" function will or does play?
>> - the RFC says: "enabled (zend.assertions=1) on development machines, >> and disabled (zend.assertions=0) in production"; a few paragraphs above >> it says "-1 - don't generate any code (zero-cost, production mode)". >> Shouldn't be -1 the default value for production then? >> > > With zend.assertions=0 in production, you'll able to switch to > zend.assertions=0 at any time. > With zend.assertions=-1 of course not.
I don't understand this. "With 'foo' in production, you will be able to switch to 'foo' at any time. With 'bar' of course not" ? Maybe I was unclear. What I meant: - a few paragraphs above it says that "-1 doesn't generate any code (zero cost)" - so why isn't THAT '-1' promoted to be the default in production php.ini instead of '0' setting?
>> - the RFC says: "A call to assert(), without a fully qualified namespace >> will call assert in the current namespace, if the function exists. An >> unqualified call to assert is subject to the same optimization >> configured by zend.assertions. ". Does this mean I can control whether a >> function in a namespace is being optimized-away with when zend.assertion >> equals -1 and otherwise do my own stuff in there and need to raise an >> AssertException on my own to signal assertion fails? >> > > Yes. you are able to eliminate your own assert() functions in namespaces.
Wow. The RFC doesn't explain this very well but I wrote this based on assumption and guesswork. This sounds two-folded to me: "very cool" (albeit I can't see a use-case right now) on one hand and "utter magic" on the other. With utter magic I mean: suddenly a function named 'assert' in a namespace is eligible to rules before ever only applied to a global existing function. I'm not saying it's bad. It's just very magic, sounds cool but could be a real PITA. Maybe just a documentation problem after all. As Pierre already mentioned, the RFC really lacks some more details. But in general, it looks good. thank you, - Markus

Leigh

11 years ago
On 20 February 2015 at 08:47, Markus Fischer <markus@fischer.name> wrote:
> This sounds two-folded to me: "very cool" (albeit I can't see a use-case > right now) on one hand and "utter magic" on the other.
Inclined to agree. @Joe what use-case prompted this feature?

Joe Watkins

11 years ago
I work on a massive codebase, 3m loc, the ability to document that we throw SomeAssertionException in *insert circumstance* is extremely appealing. It would allow us to structure the documentation and the code in a way that really makes sense especially for new developers. The alternatives are not nice, in my opinion. It's not about runtime, and the ability to catch specific exceptions by name, at all, there shouldn't be any catch blocks for AssertionExceptions in deployed code. Cheers Joe On Fri, Feb 20, 2015 at 11:06 AM, Leigh <leight@gmail.com> wrote:

Crypto Compress

11 years ago
Am 20.02.2015 um 12:27 schrieb Joe Watkins:
> I work on a massive codebase, 3m loc, the ability to document that we throw > SomeAssertionException in *insert circumstance* is extremely appealing. It > would allow us to structure the documentation and the code in a way that > really makes sense especially for new developers. The alternatives are not > nice, in my opinion. It's not about runtime, and the ability to catch > specific exceptions by name, at all,
> there shouldn't be any catch blocks for AssertionExceptions in deployed code
Hello Joe, can you please explain a bit more how you would achieve this in 3m loc? Thanks!

Crypto Compress

11 years ago
> The alternatives are not nice, in my opinion.
What are this alternatives? What are the drawbacks of "warning" in production code?

Joe Watkins

11 years ago
> can you please explain a bit more how you would achieve this in 3m loc?
AssertionExceptions are not intended to be caught, they are intended to be seen, in a specific environment. It doesn't really make sense to commit/deploy code that catches AssertionExceptions knowing that the code is actually dead in production. So you just don't deploy catch blocks for AssertionException, you might write one while debugging locally, but deploying them doesn't make sense. Cheers Joe On Fri, Feb 20, 2015 at 1:05 PM, Crypto Compress < cryptocompress@googlemail.com> wrote:

Crypto Compress

11 years ago
> AssertionExceptions are not intended to be caught, they are intended > to be seen, in a specific environment.
Joe, your argumentation is around how (not) to use exceptions. I can see your point and it's valid. My point is about not to implement exceptions at all. If exceptions are not intended to be caught, they don't need to be thrown (even if the context is different). If exceptions are not thrown and not caught, we can use "error" in dev and some easing severity (warning, zero cost nothing) in prod. Freely adapted from Murphy: If assertion exception can be catched, it will be even in production.

Pierre Joye

11 years ago
On Thu, Feb 19, 2015 at 1:09 AM, Joe Watkins <pthreads@pthreads.org> wrote:
> Morning internals, > > The expectations RFC is now in voting phase: > https://wiki.php.net/rfc/expectations#vote
I totally miss the Expectation RFC announcement. Where the RFC was actually proposed for discussions. I have been following up the DbC thread, seeing some mentions but that's it. The RFC itself popped up 3 days ago. Also the RFC itself only point to various discussions, there is no summary, details, docs, examples, etc in the RFC. I am sorry but as much I like (for what I think it does) as I like the concept, this RFC does not have, by far, the quality I would expect for a RFC being voted on. Cheers,
-- Pierre @pierrejoye | http://www.libgd.org

Dmitry Stogov

11 years ago
On Thu, Feb 19, 2015 at 6:00 PM, Pierre Joye <pierre.php@gmail.com> wrote:
> On Thu, Feb 19, 2015 at 1:09 AM, Joe Watkins <pthreads@pthreads.org> > wrote: > > Morning internals, > > > > The expectations RFC is now in voting phase: > > https://wiki.php.net/rfc/expectations#vote > > I totally miss the Expectation RFC announcement. Where the RFC was > actually proposed for discussions. > > I have been following up the DbC thread, seeing some mentions but > that's it. The RFC itself popped up 3 days ago. >
It's from 2013 and it was discussed actively during last week. Thanks. Dmitry.

Pierre Joye

11 years ago
On Thu, Feb 19, 2015 at 7:16 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> > > On Thu, Feb 19, 2015 at 6:00 PM, Pierre Joye <pierre.php@gmail.com> wrote: >> >> On Thu, Feb 19, 2015 at 1:09 AM, Joe Watkins <pthreads@pthreads.org> >> wrote: >> > Morning internals, >> > >> > The expectations RFC is now in voting phase: >> > https://wiki.php.net/rfc/expectations#vote >> >> I totally miss the Expectation RFC announcement. Where the RFC was >> actually proposed for discussions. >> >> I have been following up the DbC thread, seeing some mentions but >> that's it. The RFC itself popped up 3 days ago. > > > It's from 2013
Yes, but....
> and it was discussed actively during last week.
Still, no announce for a discussion about this specific RFC. And really, the content of the RFC is almost empty, pointing to the ML archive is really not the right way :)

Pierre Joye

11 years ago
On Thu, Feb 19, 2015 at 7:45 AM, Pierre Joye <pierre.php@gmail.com> wrote:
> On Thu, Feb 19, 2015 at 7:16 AM, Dmitry Stogov <dmitry@zend.com> wrote: >> >> >> On Thu, Feb 19, 2015 at 6:00 PM, Pierre Joye <pierre.php@gmail.com> wrote: >>> >>> On Thu, Feb 19, 2015 at 1:09 AM, Joe Watkins <pthreads@pthreads.org> >>> wrote: >>> > Morning internals, >>> > >>> > The expectations RFC is now in voting phase: >>> > https://wiki.php.net/rfc/expectations#vote >>> >>> I totally miss the Expectation RFC announcement. Where the RFC was >>> actually proposed for discussions. >>> >>> I have been following up the DbC thread, seeing some mentions but >>> that's it. The RFC itself popped up 3 days ago. >> >> >> It's from 2013 > > Yes, but.... > >> and it was discussed actively during last week. > > Still, no announce for a discussion about this specific RFC. And > really, the content of the RFC is almost empty, pointing to the ML > archive is really not the right way :)
So, back to more useful feedback. I like the concept and idea but still not sure about the custom exception vs AssertException. My gut feeling tells me that it could be better to solve that prior this vote, which actually asks to choose something we did not define yet. It could be in the same RFC (and making it more complete while being at it).
-- Pierre @pierrejoye | http://www.libgd.org

Leigh

11 years ago
On 19 February 2015 at 15:45, Pierre Joye <pierre.php@gmail.com> wrote:
> Still, no announce for a discussion about this specific RFC. And > really, the content of the RFC is almost empty, pointing to the ML > archive is really not the right way :)
There was an RFC announce thread 3 days ago. I agree 3 days is a short period of time, but the announce thread existed. Maybe it was a reply to DbC with a changed subject and your mail client didn't show it as new? I don't know, there was definitely a thread though. On 19 February 2015 at 16:06, Pierre Joye <pierre.php@gmail.com> wrote:
> I like the concept and idea but still not sure about the custom > exception vs AssertException.
Looking at the implementation, it seems that the custom exception still has to descend from AssertException https://github.com/php/php-src/pull/1088/files#diff-232f2dffbb06c0b6004724d8a498e7e7R248 That seems like a good restriction to me. You can still catch everything with AssertException but you can make it more specific if you want.

Pierre Joye

11 years ago
On Thu, Feb 19, 2015 at 9:13 AM, Leigh <leight@gmail.com> wrote:
> On 19 February 2015 at 15:45, Pierre Joye <pierre.php@gmail.com> wrote: >> Still, no announce for a discussion about this specific RFC. And >> really, the content of the RFC is almost empty, pointing to the ML >> archive is really not the right way :) > > There was an RFC announce thread 3 days ago. I agree 3 days is a short > period of time, but the announce thread existed. Maybe it was a reply > to DbC with a changed subject and your mail client didn't show it as > new? I don't know, there was definitely a thread though.
I mentioned that thread in my comment. It is still way behind what should be done when creating a new RFC, let alone pushing it to the vote phase.
> On 19 February 2015 at 16:06, Pierre Joye <pierre.php@gmail.com> wrote: >> I like the concept and idea but still not sure about the custom >> exception vs AssertException. > > Looking at the implementation, it seems that the custom exception > still has to descend from AssertException > > https://github.com/php/php-src/pull/1088/files#diff-232f2dffbb06c0b6004724d8a498e7e7R248 > > That seems like a good restriction to me. You can still catch > everything with AssertException but you can make it more specific if > you want.
I did not comment on what should be done, while I do consider this open question as a blocker to actually take a good decision for this RFC. I do think it should be discussed, answered and voted either at the same time or before this RFC.
-- Pierre @pierrejoye | http://www.libgd.org

Joe Watkins

11 years ago
There isn't legitimate technical justification for or against using custom exceptions. Since it's entirely based on preference, and the kind of utilitarian argument you can make for their use, it's acceptable that this is resolved as part of the vote. It's not a huge deal. Cheers Joe On Thu, Feb 19, 2015 at 5:34 PM, Pierre Joye <pierre.php@gmail.com> wrote:

Pierre Joye

11 years ago
On Thu, Feb 19, 2015 at 7:00 AM, Pierre Joye <pierre.php@gmail.com> wrote:
> On Thu, Feb 19, 2015 at 1:09 AM, Joe Watkins <pthreads@pthreads.org> wrote: >> Morning internals, >> >> The expectations RFC is now in voting phase: >> https://wiki.php.net/rfc/expectations#vote > > I totally miss the Expectation RFC announcement. Where the RFC was > actually proposed for discussions. > > I have been following up the DbC thread, seeing some mentions but > that's it. The RFC itself popped up 3 days ago. > > Also the RFC itself only point to various discussions, there is no > summary, details, docs, examples, etc in the RFC. > > I am sorry but as much I like (for what I think it does) as I like the > concept, this RFC does not have, by far, the quality I would expect > for a RFC being voted on.
Coming back to this point. I very much like what is presented here. However I think it is pre mature to vote on as there was (sorry) not explicit discussions about it. A couple of things are unclear. See the numerous questions in this thread. I also do not like other things. zend.assertions: I understand we need to be able to disable them. Is production vs development/debug mode specific to assertion? I do not think so, we should have a more general setting for that so other areas can be used for it. INI_SYSTEM may also reduce the usage of this feature to local development or dedicated hosts. Any shared hoster (those not allowing to change php.ini) won't be able to test in similar tests environment. It is not critical but it is something you may reconsider. assert.exceptions: Let solve the exception usages in the engine first and see how to deal with them more globally, including naming, NS or where and how they can be used. This is in my eyes a pre requise to this RFC. INI_ALL is used here. That means that just like error_reporting (which is actually very painful), calling some random codes may makes my code (caller) raised exceptions when I do not want to, or the other way round? I am not too keen on that idea. Cheers,
-- Pierre @pierrejoye | http://www.libgd.org

Laruence

11 years ago
Hey: On Thu, Feb 19, 2015 at 5:09 PM, Joe Watkins <pthreads@pthreads.org> wrote:
> Morning internals, > > The expectations RFC is now in voting phase: > https://wiki.php.net/rfc/expectations#vote
sorry, the thread is too long to read.. I am not sure whether there was some similar opinion before.. I voted without custom exception, that is because. if all assertion exception is AssertException, then we can simply optimized them away while zend.assert is disabled.. like: try { foo(); bar(); assert(); } catch (AssertException $e) { //these statements can be optimized away. } but with custom exception.. try { sqllitefunc(); // no threw sqllitefunc1(); //no threw assert("", new SqlLiteException()); } catch (SqlliteException $e) { //we are not sure maybe sqllitefunc can throw SqliteException. // thus we can not optimized these statements ayway } thanks
> > Cheers > Joe
-- Xinchen Hui @Laruence http://www.laruence.com/

Joe Watkins

11 years ago
The custom exception must derive from AssertionException, so the same optimization is possible. Cheers Joe On Fri, Feb 20, 2015 at 8:28 AM, Xinchen Hui <laruence@php.net> wrote:

Joe Watkins

11 years ago
Also, we don't optimize those away, it would not be sensible, because it's not sensible to deploy those catch blocks in the first place. Cheers Joe On Fri, Feb 20, 2015 at 8:38 AM, Joe Watkins <pthreads@pthreads.org> wrote:

Patrick Schaaf

11 years ago
Am 20.02.2015 09:47 schrieb "Joe Watkins" <pthreads@pthreads.org>:
> > Also, we don't optimize those away, it would not be sensible, because it's > not sensible to deploy those catch blocks in the first place.
So, do they become FATAL with production settings? Ideally a parse error (ideally, because then my ordinary syntax check run before deployment, could catch them :) ??? best regards Patrick

Adam Harvey

11 years ago
On 19 February 2015 at 01:09, Joe Watkins <pthreads@pthreads.org> wrote:
> The expectations RFC is now in voting phase: > https://wiki.php.net/rfc/expectations#vote
Sorry, I had an e-mail backlog while this was in discussion, so I'm only getting around to this now. Two thoughts: 1. This is awesome, particularly the BC aspects. Nice work. :) 2. For zend.assertions, is it worth defining constants with more meaningful names that can be used in place of the magic values? They're pretty arbitrary as it stands. My vote's not conditional on that — I'm +1 even in its current form — but I wonder if we can make this a little easier for users. Thanks, Adam

Pascal MARTIN

11 years ago
Le 19/02/2015 10:09, Joe Watkins a écrit :
> > The expectations RFC is now in voting phase: > https://wiki.php.net/rfc/expectations#vote >
Hi, While talking about this RFC with other people of AFUP, we discussed about assert()... And mostly ended up against "it". Still, note we probably discussed more about the idea of using assert() itself than about the RFC and the proposition of improving the existing assert() construct -- which means we probably didn't really answer the question that was asked here. Basically, the idea of adding code (assertions) directly into the code of our application in order to test for "things" doesn't feel right: we'd rather use (unit-)tests for that, alongside our application's code and not interleaved with it. Considering this, we kind of felt it wasn't really necessary to work on assertions and that enhancing them might encourage people to use them more -- adding more non-production code in the middle of the production-code. Also, using .ini directives to enable or disable the execution of portions of code comes with a risk: there is always a chance someone will mis-configure a server and assertions will run in production environment. Or maybe in some edge cases, an assertion could have some side-effect that would impact the code (even if it should not), making it work in development and not work in production? I hope I summarized our thoughts right -- and sorry if we didn't really answer the question that was asked. Thanks for your work!
-- Pascal MARTIN, AFUP - French UG http://php-internals.afup.org/

Levi Morrison

11 years ago
On Thu, Feb 19, 2015 at 2:09 AM, Joe Watkins <pthreads@pthreads.org> wrote:
> The expectations RFC is now in voting phase: > https://wiki.php.net/rfc/expectations#vote
This announcement doesn't say when voting will close and the RFC doesn't either. When do you expect voting to close?

Joe Watkins

11 years ago
Morning Internals, As mentioned on the RFC, voting finished last night at midnight. The vote passed with a majority (50%+) in favour of custom exceptions, however ... When the patch was originally written assert (expect) was a language construct, and so the exception message wasn't constructed if the assertion passed. In the current patch, assert is still a function call, so to use custom assertions would cost considerably because the custom exception is a parameter (so, +1 object per assertion regardless of result). Because of this, we are not going to merge with custom exceptions enabled, they should not be crippling, another RFC will have to be written to deal with custom exceptions if that's something we want moving forward. Cheers Joe