From: Ferruh Yigit <ferruh.yigit@amd.com>
To: "Morten Brørup" <mb@smartsharesystems.com>, dev@dpdk.org
Subject: Re: Coding Style for local variables
Date: Tue, 11 Jun 2024 16:10:33 +0100 [thread overview]
Message-ID: <190c4772-9ee5-466a-adc1-a0c4f5bb75f8@amd.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F512@smartserver.smartshare.dk>
On 6/10/2024 4:10 PM, Morten Brørup wrote:
> The coding style guide says:
>
> "Variables should be declared at the start of a block of code rather than in the middle. The exception to this is when the variable is const in which case the declaration must be at the point of first use/assignment. Declaring variable inside a for loop is OK."
>
> Since DPDK switched to C11, variables can be declared where they are used, which reduces the risk of using effectively uninitialized variables. "Effectively uninitialized" means initialized to 0 or NULL where declared, to silence any compiler warnings about the use of uninitialized variables.
>
> Can we please agree to remove the recommendation/requirement to declare variables at the start of a block of code?
>
My concern is it may break the consistency in the code.
If there is an existing function that defines N variables at the
beginning of the function, new feature defines a new variable close the
the feature block, this inconsistency bothers me more than all variables
being defined at top.
Variables being defined on top only bothers me when function is too big
and I can't see the variable declaration at the same time while I am
reading the code.
If functions is small enough to fit ~50% of my screen, locations doesn't
really matter, I can still observe (effectively) uninitialized variables
etc...
Instead of trying to optimize big functions, I am for doing other way
around to encourage smaller functions.
(Indeed I prefer 80 column limit with 8 space indentation for exact same
reason, this *artificial* limit only allows some number of indentation
and at some point forces developer to extract some part of code as new a
function.)
next prev parent reply other threads:[~2024-06-11 15:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 15:10 Morten Brørup
2024-06-10 16:11 ` Tyler Retzlaff
2024-06-10 16:31 ` Konstantin Ananyev
2024-06-20 0:38 ` Thomas Monjalon
2024-06-20 7:53 ` Morten Brørup
2024-06-20 8:09 ` Konstantin Ananyev
2024-06-20 9:02 ` Morten Brørup
2024-06-20 14:45 ` Stephen Hemminger
2024-06-11 15:10 ` Ferruh Yigit [this message]
2024-06-11 15:50 ` Stephen Hemminger
2024-06-17 14:38 ` Bruce Richardson
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=190c4772-9ee5-466a-adc1-a0c4f5bb75f8@amd.com \
--to=ferruh.yigit@amd.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
/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).