Re: Create new socket

new topic     » goto parent     » topic index » view thread      » older message » newer message
jeremy said...
euphoric said...
DerekParnell said...

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 success: {845793,938457}

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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu