lua-users home
lua-l archive

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


I think the returning nil, err from a function is useful for error reporting. Here nil is taken to mean "unable to produce meaningful data" and err is 'here is the reason why". Using false,err is not as good--false might be meaningful data. If false is not meaningful in the particular case, we can use assert(retval,err) but the more accurate assert(retval~=nil,err) works even when false is meaningful (at the cost of 5 keystrokes). IMHO, returning false,err is useful if and only if the function returns true,realdata in the case of success--itself a useful idiom in cases where failure is common, and needed in the rare case where nil is valid data. Although in that case, I would redesign the function if I had control of the code. I feel that treating nil as valid data is in general A Bad Thing (TM)....