4 ms·
Or with languages that have a better mechanism for returning multiple values. (Passing in pointers to optional results? Ick.) There's in idiom in Lua to have f
by silentbicycle 17y ago
Or with languages that have a better mechanism for returning multiple values. (Passing in pointers to optional results? Ick.)
There's in idiom in Lua to have functions return either <true, result> or <false, error message> (as two arguments, not a tuple) - consequently, it's common to say e.g. "status, f = assert(open_resource(arg, arg2))"; if it fails, the assert will fail, and open_resource will provide the error message.
In statically typed languages, returning a union type (e.g. Error | Pass of Result) also works well. Sometimes exceptions are simpler, sometimes not.