lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12/14/2012 11:42 AM, Jorge wrote:
Here comes a couple related questions:

1. when defining an API for a enable/disable type call, is nil supposed to
be accepted as false, or not? In other words, is better to force to provide
true/false, or just anything and then evaluate it to true or false?
This is:
[...]
or

----------------------
function M.feature_enable(p)
if p==true then
--enable
elseif p==false then
--disable

If you're going this route, I would insert here:
else error( "invalid value type: "..type(p), 2 )

Otherwise, what is almost certainly a logic error in the calling code will be much harder to find.

Better yet, use some way to type-check [static typing or static analysis] so that they don't need to wait until test/run time to find it, but that's a different discussion.

-- David