Re: [GIT pull] core/urgent for v5.4-rc7

From: Linus Torvalds
Date: Sun Nov 10 2019 - 17:36:02 EST


On Sun, Nov 10, 2019 at 2:01 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> trivia:
>
> This idiom '!!(logical test)' is odd and redundant.
> Logical test result is already 0 or 1, no !! is unnecessary.

You are of course correct.

I have to say, I personally have always disliked the idiomatic C "!!"
pattern. I don't think it reads well, although that's probably "C
cultural" - once you are used to the pattern, you don't think of it as
anything else.

Personally, I prefer "x != 0" over "!!x" since it reads much better to
a human, and is equally legible whether you're used to the !! pattern
or not.

C is not perl, the Obfuscated C contest not-withstanding.

And since modern C has bool, if you really want to use a cast-to-bool
instead of "x != 0", I think doing exactly that is preferable to "!!".

So I think both "x != 0" and "(bool)x" are preferable to "!!x", and
would also have made it obvious how odd and redundant the test was in
this case.

But "!!x" is shorter, of course. And it you learnt C with that pattern
it looks obvious.

Linus