Re: Clarifying confusion of our variab le placement rules caused by cleanup.h
"H. Peter Anvin" <[email protected]>
| Newsgroups | dev.linux.lists.ksummit,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On November 25, 2025 6:25:19 AM PST, Alexey Dobriyan <[email protected]> wrote: >On Tue, Nov 18, 2025 at 11:39:26AM -0500, James Bottomley wrote: > >> So which should we do? > >The best way to understand that C89 style of declaring in the beginning >of the function is pointless rule is to write some code in a language >which doesn't enforce it. You should see that nothing bad happens. > >It increases bug rate due to increased variable scope allowing typos. > >It bloats LOC -- in many cases declaration and initializer can fit >into a single line. > >It prevents adding "const" qualifier if necessary. > >Pressing PageUp and PageDown when adding new variable is pointless >busywork and distracts, breaks the tempo(flow?) so to speak. > >C89 style provokes substyles(!) which makes adding new variables even >more obnoxious: some subsystems have(had?) a rule saying that declarations >(with initializers) must be sorted by length, so not only programmer has >to PageUp to the beginning of the block, but then aim carefully and >insert new declaration. > >None of this is necessary (or possible) if the rule says "declare as low >as possible". > >There was variation of this type of nonsense with headers (not only it has >to be sorted alphabetically but by length too!) > >There is no practical difference between code and declarations: >declarations can have initializers which can be arbitrary complex, >just like "real" code. So the only difference is superficial. > > >C89 declaration style is pointless and dumb, no wonder other programming >languages dumped it (or never had), it should be simply discarded. > >It will also make Linux slightly less white crow to newcomers >(C++ doesn't have this rule after all). > Preventing the use of "const" is a big one.