DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: Thomas Monjalon <thomas@monjalon.net>
Cc: "Bruce Richardson" <bruce.richardson@intel.com>,
	"Ferruh Yigit" <ferruh.yigit@amd.com>,
	"Morten Brørup" <mb@smartsharesystems.com>,
	dev@dpdk.org, "David Marchand" <david.marchand@redhat.com>
Subject: Re: [PATCH v2] devtools: allow variable declaration inside for loop
Date: Wed, 3 May 2023 08:06:13 -0700	[thread overview]
Message-ID: <20230503150613.GA7537@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> (raw)
In-Reply-To: <2878762.e9J7NaK4W3@thomas>

On Wed, May 03, 2023 at 05:01:01PM +0200, Thomas Monjalon wrote:
> 03/05/2023 14:19, Morten Brørup:
> > > From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> > > Sent: Wednesday, 3 May 2023 12.57
> > > 
> > > On Wed, May 03, 2023 at 11:30:53AM +0100, Ferruh Yigit wrote:
> > > > Declaring variable inside for loop is not supported via C89 and it was
> > > > checked in checkpatch.sh via commit [1].
> > > > But as DPDK supported C standard is becoming C99/C11 [2], declaring
> > > > variable inside loop can be allowed.
> > > >
> > > > [1]
> > > > Commit 43e73483a4b8 ("devtools: forbid variable declaration inside
> > > for")
> > > >
> > > > [2]
> > > > https://dpdk.org/patch/121912
> > > >
> > > > Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
> > > > ---
> > > > Cc: Bruce Richardson <bruce.richardson@intel.com>
> > > > Cc: David Marchand <david.marchand@redhat.com>
> > > >
> > > > v2:
> > > >  * Update coding convention too
> > > > ---
> > > 
> > > Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> > 
> > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > 
> > [...]
> > 
> > > > @@ -558,6 +558,7 @@ Local Variables
> > > >
> > > >  * Variables should be declared at the start of a block of code rather
> > > than in the middle.
> > > 
> > > I'd love to see this restriction removed in future too. Having a
> > > variable
> > > declared on first use in the middle of block I find a far easier way of
> > > working as a) it saves scrolling to look for variable definitions and b)
> > > it
> > > makes it far easier when adding/removing blocks of code e.g. commenting
> > > out
> > > for testing,  to have all the code together rather than having variables
> > > at
> > > the top to add/remove also.
> > 
> > And c) Initializing the variables close to where they are used the first time reduces the risk of initializing them incorrectly. Especially when modifying a block of code, initialization of its variables might be missed if out of sight. (Although this is probably a consequence of "a)".)
> > 
> > I consider it old style to only declare variables at the start of a block of code, and this style of coding should be considered obsolete.
> > 
> > If you are really old (like me?), you might remember when function parameters were provided like this:
> > 
> > int main(argc, argv)
> > int argc;
> > char *argv[];
> > {
> > 	return(0);
> > }

heh, k&r C

> > 
> > We have moved on from that to a more modern coding style a long time ago. We should also move on to a more modern coding style regarding variable declarations.
> 
> Old men are used to look for variable types at the beginning of functions.
> Having only new code adopting a different style may be confusing a little.
> Note I'm not against it, just asking for more feedbacks.

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

+1 for declare in minimum necessary scope
+1 for declare at first use (enables more use of const)

thank you!

  reply	other threads:[~2023-05-03 15:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-03  9:50 [PATCH v1] " Ferruh Yigit
2023-05-03 10:02 ` Bruce Richardson
2023-05-03 10:23   ` Ferruh Yigit
2023-05-03 10:30 ` [PATCH v2] " Ferruh Yigit
2023-05-03 10:57   ` Bruce Richardson
2023-05-03 12:19     ` Morten Brørup
2023-05-03 15:01       ` Thomas Monjalon
2023-05-03 15:06         ` Tyler Retzlaff [this message]
2023-07-20  4:05           ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230503150613.GA7537@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net \
    --to=roretzla@linux.microsoft.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=mb@smartsharesystems.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).