[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Extending assert () functionality
- From: HyperHacker <hyperhacker@...>
- Date: Sun, 26 Jun 2011 06:51:38 -0600
On Sun, Jun 26, 2011 at 01:43, Lorenzo Donati
> On 25/06/2011 22.55, Rebel Neurofog wrote:
>> Well, it just will make things slower.
>> I've applied the patch for me anyway.
>> But I think it may be added to official versions.
> Please, don't get me wrong, I do think the enhancement is interesting from a
> pure syntactical point of view.
> The problem I see is that your patch adds some weight to Lua for a speed
> gain which maybe is questionable (have you tested the speed enhancement
> against a pure Lua solution?).
> Moreover, you would have a substantial speed gain only if "assert" execution
> time (in the no-errror case) is comparable to the overall execution time of
> the whole function it is placed in.
> Of course you must have tested it in your code, so this patch is convenient
> for your situation.
> As for including it in Lua's codebase, I suspect that Lua team needs to be
> convinced with more profiling data on the general case before adding weight
> to Lua.
> -- Lorenzo
As I mentioned in another thread, I think a much simpler solution
would be to allow assert() to throw things other than strings as
errors. You can do e.g. error(function() do_things() end), but you
can't do the same with assert. Those concerned about evaluation cost
can do something like:
assert(do_things(), function() compute_expensive_error_condition() end)
res, err = pcall(foo)
if (not res) and type(err) == 'function' then err()
else -- ...
Sent from my toaster.