Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Jun 2020 09:05:27 -0700 (PDT)
From:      "Rodney W. Grimes" <freebsd@gndrsh.dnsmgr.net>
To:        Warner Losh <imp@bsdimp.com>
Cc:        Ian Lepore <ian@freebsd.org>, Kristof Provost <kp@freebsd.org>, Ed Maste <emaste@freebsd.org>, Toomas Soome <tsoome@freebsd.org>, src-committers <src-committers@freebsd.org>, svn-src-all <svn-src-all@freebsd.org>, svn-src-head <svn-src-head@freebsd.org>
Subject:   Re: svn commit: r362217 - head/stand/common
Message-ID:  <202006171605.05HG5Rtu085964@gndrsh.dnsmgr.net>
In-Reply-To: <CANCZdfo0R6LDB_VVxO1rMxFkQ6ygCCFioWbiMoFJE0KL5hY46w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
[ Charset UTF-8 unsupported, converting... ]
> On Tue, Jun 16, 2020 at 8:33 PM Ian Lepore <ian@freebsd.org> wrote:
> 
> > On Tue, 2020-06-16 at 19:34 +0200, Kristof Provost wrote:
> > > On 16 Jun 2020, at 19:11, Ed Maste wrote:
> > > > On Tue, 16 Jun 2020 at 13:01, Ian Lepore <ian@freebsd.org> wrote:
> > > > >
> > > > > As much as I prefer doing it this way, style(9) doesn't allow for
> > > > > variable declarations inside a for() statement (or even inside a
> > > > > local
> > > > > block, which is just too 1980s for me, but it is still our standard).
> > > >
> > > > Perhaps it's time to update style(9) to at least permit these uses, as
> > > > we've done with the blank line at the beginning of functions with no
> > > > local variables, and with braces around single-line bodies.
> > >
> > > We have 431 instances of `for (int i` in sys alone. It?s not so much a
> > > question of allowing it as acknowledging reality at this point.
> > >
> > > Best regards,
> > > Kristof
> >
> > Hmm, so we do.  If you weed out sys/contrib, and device drivers
> > contributed by vendors, the number is a lot smaller, but still big
> > enough that we should just change the rules I think.
> >
> 
> We should definitely just change the rules. There's no point in
> prohibiting it. Contributors have already voted with their feet
> 
> diff --git a/share/man/man9/style.9 b/share/man/man9/style.9
> index 4e801bbcbe70..fd23d573eb00 100644
> --- a/share/man/man9/style.9
> +++ b/share/man/man9/style.9
> @@ -592,8 +592,6 @@ not
>  Parts of a
>  .Ic for
>  loop may be left empty.
> -Do not put declarations
> -inside blocks unless the routine is unusually complicated.

Perhaps some wording here that makes it explicit that
block scope variables are allowed, and that the for()
case is allowed.

>  .Bd -literal
>         for (; cnt < 15; cnt++) {
+	for (int cnt = 0; cnt < 15; cnt++) {
+		char *p;
>                 stmt1;

This updates the example to reflect the new accepted style.

> 
> Although the block doesn't start until { so int i; in the commit
> technically doesn't violate this rule. We violate it in dozens of other
> ways than this.

I think it violates some other rule about declarations being
in order of size sorted at the top of a routine, perhaps that
needs looked at as well for some change.

> Warner
-- 
Rod Grimes                                                 rgrimes@freebsd.org



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