[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Disabling assert function
- From: HyperHacker <hyperhacker@...>
- Date: Thu, 20 May 2010 14:52:11 -0600
On Wed, May 19, 2010 at 23:49, Henk Boom <henk@henk.ca> wrote:
> On 19 May 2010 22:42, David Manura <dm.lua@math2.org> wrote:
>>
>> On Wed, May 19, 2010 at 6:51 AM, Nikolai Kondrashov <spbnick@gmail.com>
>> wrote:
>> > I wasn't able to find an answer to a seemingly basic question anywhere:
>> > Is it possible to disable "assert" function execution along with its
>> > argument evaluation in Lua? I.e. like it is done in C by defining
>> > NDEBUG?
>>
>> An observation: In many languages [1], asserts are clearly
>> distinguished from normal error handling: assert calls should have no
>> meaningful side-effects, so you may safely strip them, and any assert
>> failure indicates a defect in the program. In Lua, assert is also
>> conventionally used for its convenience in converting normal error
>> return values into raised exceptions (the inverse of pcall). The Lua
>> manual contains one such possible example: assert(loadstring(s))() .
>> This we might say is an abuse of the normally recognized concept of
>> assert and could call for splitting assert into two separate functions
>> (even if they be implemented identically).
>>
>> [1] http://en.wikipedia.org/wiki/Assertion_(computing)
>
> David brings up a really important point.
> Especially note that assert has return values, and so uses of assert in
> expression contexts are one example of where simply removing them does not
> work. It seems to me that assert in lua plays a very different role than
> assert in languages such as c (where it can be removed with NDEBUG) and java
> (where it is turned off by default!). Maybe instead of removing assert,
> which has an established role in lua, a new construct specifically intended
> for side-effect-free checks should be used.
> henk
Maybe 5.2 or a patch could add a debug.assert(cond, message) which
compiles to nothing unless the compiler is given a certain flag?
--
Sent from my toaster.