ES4 draft: assert expression

David Flanagan david at davidflanagan.com
Tue Apr 15 11:05:26 PDT 2008


Lars Hansen wrote:

 > Since there is no way to turn off asserts the program can
 > (correctly) come to depend on the evaluation of the assertion.
 > And I think your point is therefore a good one, though
 > I don't know if it outweighs the benefits of (re)using a
 > common name for this functionality.

Hi everyone.  I've been lurking in the archives, but this is the first 
time I've felt compelled (and able) to reply...

If there is no way to turn assertions off, and since the spec requires 
the parentheses around the assertion, I don't see what is gained by 
making this a expression instead of a global function. If all this spec 
offers is standardization of the error reporting information in the 
exception objects, I'm not sure that's worth it.

It doesn't look like this proposal has made it to the spreadsheet, and I 
haven't read whatever previous discussion spurred it, but it doesn't 
seem to me that it is worth doing as it stands.

 > (The inability to turn off asserts may in itself be a weakness,
 > so maybe that's where the problem lies.  But it is unclear
 > how we would handle that problem in practice.)

I assume that the ideal way to turn assertions on and off must be 
outside the language as part of the embedding.  But wouldn't a pragma 
like 'use assertions' be better than nothing?  That way developers 
transitioning their code from development to production wouldn't have to 
go through and comment their assertions out, they'd just have to go and 
remove  a pragma.

While on the topic of assertions and pragmas, if 'use strict' ends up 
checking for and warning about statements with no side effects, I 
imagine it could also check for and warn about assertions that obviously 
do have side effects...  Not foolproof, but it could catch the case 
where someone writes = instead of ==, for example.

Of course, I get the impression that the true es4 approach (and this is 
a joke, I think) is to allow blocks of code to be placed in namespaces, 
and to allow the execution of those blocks to be turned on with 'use'. 
Kind of like #ifdef.  With that in place, then the assert expression 
would be syntax sugar for placing the assertion in the the assertions 
namespace, and 'use assertions' would turn on the execution of 
assertions :-)

     David Flanagan



More information about the Es4-discuss mailing list