tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Rationale for some rules in style guide



On Tue, Apr 11, 2023 at 08:30:19PM +0200, Roland Illig wrote:
> 
> The style guide says:
> > When declaring variables in functions declare them sorted by size
> 
> What is the purpose of this rule, and is it still useful? I'd rather see
> the variables grouped by topic. If that rule's purpose is to help some
> ancient compiler lay out the variables efficiently, I don't see a point
> in keeping that rule, as modern compilers are advanced enough.
> 

To save stack space?  If you mix up the sizes of the variables then
there would be wasted memory due to alignment constraints for accessing
a certain sized variable.  Those constraints are processor not compiler
artifacts.  Unless compilers are smart enough to reorder the variables
to pack them efficiently in memory then it is still a good idea to do
this

> > then in alphabetical order
> 
> Why does it make sense to sort variables in the order 'bottom, left,
> right, top' instead of the natural pronunciation order 'top, left,
> bottom, right', for example? Or 'height, width, x, y' instead of 'x, y,
> width, height'?
> 

More of a readability thing I think - if the variable names are sorted
and you are looking for "indicator" then you can stop after "height".
You can be confident you have not missed the variable in the noise.

-- 
Brett Lymn
--
Sent from my NetBSD device.

"We are were wolves",
"You mean werewolves?",
"No we were wolves, now we are something else entirely",
"Oh"


Home | Main Index | Thread Index | Old Index