On Mon, Mar 10, 2025 at 10:41 AM Larry McVoy <lm(a)mcvoy.com> wrote:
On Mon, Mar 10, 2025 at 03:12:06AM -0600,
arnold(a)skeeve.com wrote:
I think, as in all things, "always use
parentheses" can be carried
too far. I find
if (a == b && c == d)
perfectly reasonable, but
if ((a == b) && (c == d))
to be just silly.
Color me silly then. My eyes parse the "silly" form faster. And I was the
boss so my eyes won. Over time, everyone at my shop came to agree with me.
One mans silly is another mans faster reading.
If you worked for me, you did the silly form. And everyone came around to
liking it. It's just faster to read.
I'm with Arnold on this one in terms of preference, but I think
there's a meta point that's interesting to consider: style
localizations facilitate understanding and knowledge transfer across
large code bases. Google has a codebase measured in the BLOC (B as in
billion), and very strict style guides; they're really more hard and
fast rules as opposed to a soft thing that the term "guide" tends to
imply.
Personally, I hated Google's style formats; but after a month or two
they largely disappeared for me and I stopped thinking about them. I
still thought and continue to think they're ugly, but the network
effects of being able to `cd` anywhere in that massive monorepo and be
able to read a file without the cognitive overhead of internalizing
that this programmer preferred to put the braces somewhere else
relative to the last programmer was a huge win, far outweighing my
aesthetic objections. This directly contributed to allowing the
organization to scale to tens of thousands of programmers working in
the same code base simultaneously. Supported by tools like automatic
formatters, folks concentrated on the problem at hand and not the
minutiae of formatting. Uniform style also facilitated things like
large-scale, automated refactorings; another huge win in evolving code
to newer standards, fixing old problems, and so forth. So even though
I didn't like the specifics of the local standard, I respected what it
did for us.
So I don't think the specifics of whether you put parentheses around
every boolean expression matter as much as whether you aggressively
commit to consistency everywhere and support that with tooling and
automation.
- Dan C.