PHP 10.0 Blog

What if…

faster, better assert

Posted by Stas on October 26, 2006

For now, assert() function is described as debug function and internally is eval() with checks. Continuing the inlining theme (looks like I think a lot about inlining, don’t I) I’d like to have assert which can:

  • Pre-compile the expression inside, i.e. most of the times I don’t really need to recompile the expression, just substitute variables.
  • Can be quickly turned into no-op if I don’t want it – meaning, just function receiving true/false is not enough, since I can’t no-op it quickly.
  • Of course, can be told what to do if assertion fails, just like the old one.

This can allow people to generate quite efficient pre/post-condition code easily, and turn it on and off on request. I.e. I see my app misbehaving, I turn on asserts, I run it, some assert breaks and I get the full trace of what happened even not touching a debugger once. Not that debugger is something bad – but debugger can’t efficiently checks pre/post-conditions either.
Which brings me to another idea of connecting debugger to these asserts – but debugger should be able to connect to errors (IIRC, some debuggers can now – it’s very easy to do from debugger’s point of view anyway) so if failed assert produces an error that should be enough.

About these ads

One Response to “faster, better assert”

  1. [...] faster, better assert [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: