ksummit.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Bird, Tim" <Tim.Bird@sony.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	"ksummit@lists.linux.dev" <ksummit@lists.linux.dev>,
	Dan Williams <dan.j.williams@intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: Clarifying confusion of our variable placement rules caused by cleanup.h
Date: Sat, 17 Jan 2026 23:32:41 +0000	[thread overview]
Message-ID: <20260117233241.5ba95b2d@pumpkin> (raw)
In-Reply-To: <PH0PR13MB5639535AC3D1232831FD2380FD8AA@PH0PR13MB5639.namprd13.prod.outlook.com>

On Sat, 17 Jan 2026 16:54:43 +0000
"Bird, Tim" <Tim.Bird@sony.com> wrote:

> > -----Original Message-----
> > From: Alexey Dobriyan <adobriyan@gmail.com>
> > 
> > On Fri, Jan 02, 2026 at 09:50:29AM -0500, Steven Rostedt wrote:  
> > > On Wed, 31 Dec 2025 13:17:32 +0100
> > > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > >  
> > > > > There was variation of this type of nonsense with headers (not only it has
> > > > > to be sorted alphabetically but by length too!)  
> > > >
> > > > By length it indeed sounds weird, but alphabetical is the natural language
> > > > order everybody learnt from the daycare / school years, so it's properly
> > > > programmed in our deep brain. Having that allows to find easily if anything one
> > > > is interested in is already being included. Also it allows to avoid dup inclusions
> > > > (was there, fixed that for real). So, it's not bad.  
> > >
> > > Actually, I like the "by length" because its aesthetically easier on the eyes.
> > >
> > > Alphabetically is fine, but either one helps in catching duplicate headers.  
> > 
> > Such rules for headers are mostly harmless -- headers are supposed to be
> > idempotent so ordering doesn't matter. But if ordering doesn't matter
> > why have a rule at all?  

> The rule is (or at least was, at one point) helpful to reduce the likelihood
> merge conflicts during patch application.  I know patch and quilt still
> don't ignore mismatched #include lines in the patch context, even
> though #include lines in C are independent of each other.  I'm not sure if git
> handles this better or not.

I prefer headers to be grouped with system headers first, then subsystem ones
and finally local ones.

Alphabetic ordering is, IMHO. silly.
If you know the name of something you cam search for it.
When you don't know the name you want it to be near something you do know.
So in a book on a cpu instruction set you want all the arithmetic
instructions next to each other not spread throughout the book.

For C variables you want the definition where you can quickly find it when
looking at the code.
Hiding it in the middle of a large block of statements doesn't help
(especially if -Wshadow isn't enabled when you might find the wrong one).
If a variable is only used in a very short block, it can be defined at the
top of the block - otherwise it really needs to be at the top of the function.
But don't initialise things that aren't semi-constant and are only used way
down the function - that just makes you have to go hunting for a value.

The location of these definitions has to be about making code easier to
quickly read.

	David

> 
> When everyone appends new #include lines at the end of the block of lines,
> there is more likelihood of a patch conflict right there.  If the #include lines
> are instead sorted in some fashion, it reduces (but obviously does not eliminate)
> the possibility of a patch conflict.
>  -- Tim
> 


  reply	other threads:[~2026-01-17 23:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 16:39 James Bottomley
2025-11-18 17:18 ` Bart Van Assche
2025-11-18 18:38   ` Linus Torvalds
2025-11-18 19:04     ` Bart Van Assche
2025-11-18 19:14       ` Linus Torvalds
2025-11-18 20:43         ` Al Viro
2025-11-18 19:15       ` H. Peter Anvin
2025-11-18 19:11     ` H. Peter Anvin
2025-11-18 19:16       ` Linus Torvalds
2025-11-18 19:19         ` H. Peter Anvin
2025-11-18 19:17     ` Steven Rostedt
2025-11-18 19:22       ` Linus Torvalds
2025-11-18 19:56         ` Steven Rostedt
2025-11-18 20:23           ` Linus Torvalds
2025-11-18 21:05             ` Linus Torvalds
2025-11-18 20:21       ` James Bottomley
2025-11-18 20:30         ` Linus Torvalds
2025-11-18 20:51         ` Steven Rostedt
2025-11-18 21:10           ` James Bottomley
2025-11-18 22:34             ` Steven Rostedt
2025-11-18 23:32               ` James Bottomley
2025-11-18 19:23 ` H. Peter Anvin
2025-11-18 20:28   ` James Bottomley
2025-11-25 13:09 ` Jani Nikula
2025-11-25 14:25 ` Alexey Dobriyan
2025-11-25 15:32   ` Stephen Hemminger
2025-11-25 16:04   ` Steven Rostedt
2025-11-25 17:57   ` H. Peter Anvin
2025-12-31 12:17   ` Andy Shevchenko
2026-01-02 14:50     ` Steven Rostedt
2026-01-17 16:23       ` Alexey Dobriyan
2026-01-17 16:54         ` Bird, Tim
2026-01-17 23:32           ` David Laight [this message]
2026-01-18 16:04         ` Steven Rostedt
2026-01-18 19:12           ` Paul E. McKenney
2026-01-18 19:17           ` James Bottomley
2026-01-18 19:33             ` Dan Carpenter
2026-01-18 19:52               ` Joe Perches
2026-01-18 21:07             ` Steven Rostedt

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=20260117233241.5ba95b2d@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=Tim.Bird@sony.com \
    --cc=adobriyan@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dan.j.williams@intel.com \
    --cc=ksummit@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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