From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Changli Gao <xiaosuo@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
Patrick McHardy <kaber@trash.net>,
"David S. Miller" <davem@davemloft.net>,
netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] netfilter: save the hash of the tuple in the original direction for latter use
Date: Fri, 20 Aug 2010 09:43:14 -0400 [thread overview]
Message-ID: <20100820134314.GA3283@Krystal> (raw)
In-Reply-To: <AANLkTinA3-KMPKJa-66QCMUpbDFwey2mjE=VN=9=zg=6@mail.gmail.com>
[ executive summary: trying to explain why static variable declarations
within the body of functions is bad in kernel code. ]
* Changli Gao (xiaosuo@gmail.com) wrote:
> On Fri, Aug 20, 2010 at 12:11 AM, Mathieu Desnoyers
> <mathieu.desnoyers@polymtl.ca> wrote:
> >
> > Ah, I see. But I think the static variable should stay declared outside
> > of the function scope, with a nice comment explaining why it's not
> > initialized at init-time.
> >
> > Hiding global state in function code is usually frowned upon.
> >
>
> I don't agree with you. We'd better not expose the variable which
> isn't expected to be used by others. If not, maybe someone will misuse
> it.
We are talking about a static variable usable only within a single file,
where is the problem ? A nice comment can have this effect.
> The user should only reply on the interface, but not the internal
> implementation.
I'm talking about good practice to help code review. This is way more
important than the potential "encapsulation" benefit of hiding global
state (a static variable) within the body of a function.
I remember that Andrew Morton has strong opinions about this, and I
remember being in complete agreement with him on the topic.
Thanks,
Mathieu
>
> Thanks.
>
> --
> Regards,
> Changli Gao(xiaosuo@gmail.com)
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
prev parent reply other threads:[~2010-08-20 13:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-19 14:33 [PATCH v2] netfilter: save the hash of the tuple in the original direction for latter use Changli Gao
2010-08-19 15:21 ` Mathieu Desnoyers
2010-08-19 15:35 ` Changli Gao
2010-08-19 15:41 ` yao zhao
2010-08-19 15:46 ` Eric Dumazet
2010-08-19 16:11 ` Mathieu Desnoyers
2010-08-19 23:10 ` Changli Gao
2010-08-20 13:43 ` Mathieu Desnoyers [this message]
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=20100820134314.GA3283@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kaber@trash.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=xiaosuo@gmail.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).