[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: nil, err idiom (was Re: Quest: real world "Lua array with holes" usage)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 25 Jul 2016 09:46:39 +0200
2016-07-25 0:44 GMT+02:00 Michael Nelson <mikestar1313@gmail.com>:
> 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)
There is one such case in the standard library: 'require'. A module that
loads successfully but returns nil, produces the return value "true".