Re: [GIT pull] core/urgent for v5.4-rc7
From: Linus Torvalds
Date: Mon Nov 11 2019 - 12:12:36 EST
On Sun, Nov 10, 2019 at 5:50 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> The !! logical usage is not particularly common in the kernel.
> There seems to be only a couple/few dozen.
Your grep pattern is for the explicitly silly "turn a boolean to a
boolean". That should certainly be rare.
But I meant it in a more general way - there's a lot of common use of
"!!" for "turn this expression into a boolean". A trivial grep for
that (didn't check how correct it was - there might be comments that
are very excited too) implies that we have a fair amount of this
pattern:
$ git grep '[^!]!![^!]' -- '*.[ch]' | wc -l
7007
so the '!!' pattern itself isn't rare.
It's so common that the fact that people then occasionally get
confused and over-use it a bit in contexts where it's already boolean
isn't so surprising.
Personally, I still find that pattern non-intuitive, even when used
correctly. Double negatives aren't considered good in English, I don't
find it all that natural in C either.
But it's a pattern, it's idiomatic, and it's certainly not worth
forcing my own personal quirk on other people, so I won't accept
scripted patches to change it.
The one pattern I _really_ hate is the thing that some people are
taught to do: using "5 == x" instead of "x == 5" because it really
reads completely bogusly to me. Some people are taught that pattern
because it minimizes the risk of confusion between "==" and "=", and I
think that's completely wrong-headed.
Trying to teach people to write illegible code just to catch a syntax
error is crazy. You're "fixing" the wrong thing.
Oh well. We have a couple of those in the kernel too. And I'm not
going to enforce my personal quirks there either, even if I'm
ClearlyRight(tm) and hold the OnlyCorrectOpinion(tm) in this matter.
Linus