You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by Daniel Quinlan <qu...@pathname.com> on 2004/03/02 09:13:44 UTC

error return code

Theo,

I think we need to discuss this one on the mailing list.

> theo: in the SA code, do you think we should be doing return code of 0
>       is error, or 0 is ok?
> theo: I'm finding some of our code does one and some does the other.
> theo: we should pick one.
> ***theo picks 0 means error

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: error return code

Posted by Daniel Quinlan <qu...@pathname.com>.
Justin Mason <jm...@jmason.org> writes:

> +1 on "1 means OK, 0/undef means error".  IMO, undef is more
> appropriate and perlish.

-0.9 on changing all the "return 0" statements in the code to undef, -1
without a reason.

0 means false and it is used to indicate 0 bytes, 0 offset, 0 count,
etc.  It sometimes has a dual context, so making every "false" an undef
*will* break stuff which is hardly appropriate.

undef is generally more appropriate when the return code is a byte
offset, size, or something else where 0 is a possible correct response.

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: error return code

Posted by Theo Van Dinter <fe...@kluge.net>.
On Tue, Mar 02, 2004 at 11:29:01AM -0800, Dan Quinlan wrote:
> in my earlier email is that it would be nice if we had a way to indicate
> that a rule did not run (which is different than saying it didn't
> match).  We could use that information to potentially get rid of score

Wouldn't be hard.  I'd say 1 means hit, 0 means didn't hit, undef means
didn't run.  In theory, all rules should run, so there's no reason that
the result should be undef unless it didn't run.

-- 
Randomly Generated Tagline:
Windows: Where do you want to go today?
 MacOS  : Where do you want to be tomorrow?
 Linux  : Are you coming or what?
         - June 2000 issue of Linux Journal

Re: error return code

Posted by Daniel Quinlan <qu...@pathname.com>.
>> Ok, but I picked 0 means error and 1 means ok as is standard in most
>> perl modules and the rest of our code.  Lets this type of thing work:

I agree 0 generally means error, although Michael is correct in pointing
out it really means false.  There are cases where you want to use a
negative number or undef to indicate an error, though.

The related return code issue I wanted to discuss, but I didn't get to
in my earlier email is that it would be nice if we had a way to indicate
that a rule did not run (which is different than saying it didn't
match).  We could use that information to potentially get rid of score
sets.  Each rule could then only have two potential scores: "hit" and
"not run" (the third state of "not hit" always has a score of zero for
simplicity).

Daniel

-- 
Daniel Quinlan                     anti-spam (SpamAssassin), Linux,
http://www.pathname.com/~quinlan/    and open source consulting

Re: error return code

Posted by Michael Parker <pa...@pobox.com>.
On Tue, Mar 02, 2004 at 10:35:29AM -0500, Theo Van Dinter wrote:
> On Tue, Mar 02, 2004 at 12:13:44AM -0800, Dan Quinlan wrote:
> > I think we need to discuss this one on the mailing list.
> > 
> > > theo: in the SA code, do you think we should be doing return code of 0
> > >       is error, or 0 is ok?
> > > theo: I'm finding some of our code does one and some does the other.
> > > theo: we should pick one.
> > > ***theo picks 0 means error

Well, I'd say 0 is false.  What false means as a return value is up to
the caller.

> Ok, but I picked 0 means error and 1 means ok as is standard in most
> perl modules and the rest of our code.  Lets this type of thing work:
> 
> $value = do_a() || do_b() || do_c();
> 

In this case, caller assumes that a 0/undef/'' (ie false) return value
is an error and will continue processing.

> I haven't checked all of the code, since I was just doing stuff in the
> Bayes section yesterday, but ...

Yeah, a whole lot of that was legacy code, I have good intentions to
go in and do more cleanup in this code.  One day....One day

Michael

Re: error return code

Posted by Matt Sergeant <ms...@startechgroup.co.uk>.
On Tue, 2 Mar 2004, Theo Van Dinter wrote:

> On Tue, Mar 02, 2004 at 12:13:44AM -0800, Dan Quinlan wrote:
> > I think we need to discuss this one on the mailing list.
> > 
> > > theo: in the SA code, do you think we should be doing return code of 0
> > >       is error, or 0 is ok?
> > > theo: I'm finding some of our code does one and some does the other.
> > > theo: we should pick one.
> > > ***theo picks 0 means error
> 
> Ok, but I picked 0 means error and 1 means ok as is standard in most
> perl modules and the rest of our code.  Lets this type of thing work:
> 
> $value = do_a() || do_b() || do_c();
> 
> I haven't checked all of the code, since I was just doing stuff in the
> Bayes section yesterday, but ...

I have a presentation about using return codes.

  http://axkit.org/docs/presentations/tpc2002/exceptions.pdf

Just so you know my opinion.

The above turns into:

eval { do_a(); do_b(); do_c() };
if ($@) {
  # process exception
}

(I put it all on one line to be more equivalent to your || example)

It has the benefit that if you *don't* catch it then at least it gets 
found out about somewhere up the stack. Anyone who tells me that they've 
never ignored an error return code has probably never used perl's print 
function.

Matt.


Re: error return code

Posted by Theo Van Dinter <fe...@kluge.net>.
On Tue, Mar 02, 2004 at 12:13:44AM -0800, Dan Quinlan wrote:
> I think we need to discuss this one on the mailing list.
> 
> > theo: in the SA code, do you think we should be doing return code of 0
> >       is error, or 0 is ok?
> > theo: I'm finding some of our code does one and some does the other.
> > theo: we should pick one.
> > ***theo picks 0 means error

Ok, but I picked 0 means error and 1 means ok as is standard in most
perl modules and the rest of our code.  Lets this type of thing work:

$value = do_a() || do_b() || do_c();

I haven't checked all of the code, since I was just doing stuff in the
Bayes section yesterday, but ...

-- 
Randomly Generated Tagline:
"President Bush met with Pakistani President Musharraf today. And you
 could tell Bush has limited experience with Pakistanis. Every time the
 conversation with Musharraf came to a stop, Bush would ask him to turn
 off the meter."
         - Bill Maher, Politically Incorrect