I'm not a frequent contributor on internals but I think a little something
is being missed here.
Passing callable instead of boolean (or something that converts to boolean)
is the altnerate way of making asserts fast without making them a language
construct (in other programming languages).
Showing by example. Forget about language construct assert and assuming
its simply a function.
Example 1: assert takes boolean
$func = function(){ /* stuff */ }
assert(func())
in dev and production environments, func() is evaluated before assert is
called.
Example 2: assert takes callable
$func = function(){ /* stuff */}
assert(func)
In dev environments, assert calls func, but in production environments,
assert returns immediately and func is never called.
My understanding is that adding language level constructs adds overhead to
the language as a whole. In my mind, assert taking callable should be an
ALTERNATIVE to assert as a language level construct.
Thanks and lemme know if I'm misunderstanding,
Will Bartlett
--
William Bartlett
College of Engineering | Cornell University '14
240-432-5189
On Wed, Feb 5, 2014 at 2:21 AM, Yasuo Ohgaki <[email protected]> wrote:
> Hi Dmitry,
>
> On Wed, Feb 5, 2014 at 3:38 PM, Dmitry Stogov <[email protected]> wrote:
>
> > but we can write:
> >
> > $f = function() {return FALSE;};
> > assert($f());
> >
>
> I'll use this form, if assert() does not support direct closure call.
> Direct call seems cleaner to me.
>
> assert(function() {
> // Do complex assertion here.
> };
>
> Users are used to this form because of JavaScript popularity.
> It's a small difference, but I hope new assert() supports this :)
>
> Regards,
>
> P.S. Thank you for the declare(pre/post_hook) comment. I'll look
> into VM when I have time.
>
> --
> Yasuo Ohgaki
> [email protected]
>