Re: [RFC PATCH 1/5] builtin/checkout: avoid usage of '!!'
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 21, 2017, 01:31 UTC
- Message-ID
- <xmqqlgl8n8fn.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <fbe3d3e2-a14c-fe7c-7e5d-c24789b249ca@gmail.com>
Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> writes:
Show 6 quoted lines
> Wait, I missed a contradiction here. > .. > Documentation/SubmittingPatches says: > >> - Some clever tricks, like using the !! operator with arithmetic >> constructs, can be extremely confusing to others.
What does "with arithmetic constructs" mean? Would it refer to things like
!!i != !!(j + 3)
that unnecessarily obfuscates what is going on?
The primary reason why !!ptr is good in the code that this patch touches is because what is doubly negated is a pointer, not an integer or other things. The called function does *not* limit its input to 0 or 1 (it wants 0 for false and everything else for true), so we wouldn't be doing !!i if what we are passing is already an integer. But we cannot just pass a pointer to such a parameter without getting the compiler upset.