Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Mar 2002 22:13:50 +0200
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        hackers@freebsd.org
Subject:   RFC: style(9) isn't explicit about booleans for testing.
Message-ID:  <20020305201350.GC4820@hades.hell.gr>

next in thread | raw e-mail | index | archive | help
The following is the largest part of the audit trail of PR docs/28555.

At the end of the audit trail, Dima Dorfman asked Mike Meyer to seek review
and comments from a wider audience than -doc.  Since this documentation PR
has been open for quit some time now, I'm posting the patch the PR was
about, hoping to get comments from our style(9) meisters, and everyone else
that can help with this.

Giorgos Keramidas                       FreeBSD Documentation Project
keramida@{freebsd.org,ceid.upatras.gr}  http://www.FreeBSD.org/docproj/

--- Audit trail ---

On 2001-06-30 21:26, Mike Meyer wrote:
> The style(9) page says not to use ! for testing values unless the
> value is a boolean. It also says to test pointers against NULL. This
> leaves open the question of how other values that aren't booleans
> should be tested.
> 
> >How-To-Repeat:
> 
> Read the man page to try and decide if you should write "if (x)" or
> if (x != 0).
> 
> >Fix:
> 
> Apply the attached page to the style(9) man page.
> 
> --- /usr/src/share/man/man9/style.9	Fri May 18 07:27:37 2001
> +++ style.9	Sat Jun 30 16:23:34 2001
> @@ -449,14 +449,37 @@
>  !(p = f())
>  .Ed
>  .Pp
> -Don't use '!' for tests unless it's a boolean, e.g. use
> +For tests, always compare the value to the appropriate 0 instead of
> +checking it directly, unless the value is a boolean.
> +For pointers, use:
> +.Bd -literal
> +if (p != NULL)
> +.Ed
> +.Pp
> +not
> +.PP
> +.Bd -literal
> +if (!p)
> +.Ed
> +.Pp
> +For other values, use:
>  .Bd -literal
>  if (*p == '\e0')
>  .Ed
>  .Pp
>  not
>  .Bd -literal
> -if (!*p)
> +if (*p)
> +.Ed
> +.Pp
> +unless the value is a boolean. In that case, use:
> +.Bd -literal
> +if (p)
> +.Ed
> +.Pp
> +and
> +.Bd -literal
> +if (!p)
>  .Ed
>  .Pp
>  Routines returning void * should not have their return values cast


On 2002-06-30 21:57, Dima Dorfman wrote:
> I think it is quite clear on the subject.  If it's not a boolean,
> don't treat it like one; i.e., compare it against the value you're
> looking for.  '0' may not always be that value.
>  
> Regardless, this does not belong as a PR, let alone in the docs/
> category.  It belongs as a post on -hackers, asking what people think,
> not as a change request.  Since *developers* are expected to follow
> style(9), it is the *developers* (i.e., -hackers@) that you should be
> proposing the change to.


On 2001-06-30 22:55, Mike Meyer wrote:
> We both agree I'm not proposing a change in the style they have to
> follow; I'm just proposing making something explicit instead of
> implicit. As such, I'm not sure it warrants discussion. If the PR
> belongs in another category, please feel free to move it to either
> move it or suggest one for someone else to move it to.


On 2001-06-02 23:13, Dima Dorfman wrote:
> I'm not suggesting that you should get every developer's approval, but
> I am suggesting that wider review than the -doc list would be nice,
> esp. for a document that defines policy.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020305201350.GC4820>