Re: Create new socket
- Posted by euphoric (admin) Aug 25, 2009
- 938 views
It should be an object that is returned. If this is -1 then an error occured. A valid socket happens to be a two-element sequence.
Why not return a sequence on FAIL as well, such as {-1,0}?
Why would you?
Because then I don't have to use the ambiguous "object" type identifier.
Instead of
x = thefunc() if not atom(x) then...
I can use
x = thefunc() if x[1] > 0 then...
This assumes that a sequence type is more efficient than using an object type.
But it also just seems more logical and reasonable to return a consistent result.
On fail: {-1,0}, or even {-1}
Throughout BBCMF, function results are returned as follows:
{ 1, result } for success, where result can then be in any format
{ 0, result } for fail, where result is usually an error message or code
if result[1] then -- process result[2] else -- display result[2] end if
It has made things quite efficient, especially during development.
The primary thing is, I get rid of an ambiguous and inefficient "object" type declaration.