Git development
 help / color / mirror / Atom feed
* [PATCH] CodingGuidelines: !! is not all that exotic
@ 2026-11-18 18:31 Junio C Hamano
  2026-11-19 10:44 ` Phillip Wood
  2026-11-19 15:15 ` Kristoffer Haugsbakk
  0 siblings, 2 replies; 3+ messages in thread
From: Junio C Hamano @ 2026-11-18 18:31 UTC (permalink / raw)
  To: git

Remove the clause against "clever tricks" that cites !!value that is
a standard technique to normalize a value to 0/1 boolean.  We could
resurrect it if we can come up with a truly exotic example that we
would want to avoid, but this is not a good enough justification for
this rule.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I think we saw a good example that !! was used in a recent review
   thread, and the idea to remove this rule was floated back then,
   but without following through.

 Documentation/CodingGuidelines | 4 ----
 1 file changed, 4 deletions(-)

diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines
index 3c8d6c7dd3..4bfa615bac 100644
--- c/Documentation/CodingGuidelines
+++ w/Documentation/CodingGuidelines
@@ -522,10 +522,6 @@ For C programs:
 	    that_is_used_in + a_very_long_expression) {
 		...
 
- - Some clever tricks, like using the !! operator with arithmetic
-   constructs, can be extremely confusing to others.  Avoid them,
-   unless there is a compelling reason to use them.
-
  - Use the API.  No, really.  We have a strbuf (variable length
    string), several arrays with the ALLOC_GROW() macro, a
    string_list for sorted string lists, a hash map (mapping struct

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] CodingGuidelines: !! is not all that exotic
  2026-11-18 18:31 [PATCH] CodingGuidelines: !! is not all that exotic Junio C Hamano
@ 2026-11-19 10:44 ` Phillip Wood
  2026-11-19 15:15 ` Kristoffer Haugsbakk
  1 sibling, 0 replies; 3+ messages in thread
From: Phillip Wood @ 2026-11-19 10:44 UTC (permalink / raw)
  To: Junio C Hamano, git

Hi Junio

On 18/11/2026 18:31, Junio C Hamano wrote:
> Remove the clause against "clever tricks" that cites !!value that is
> a standard technique to normalize a value to 0/1 boolean.  We could
> resurrect it if we can come up with a truly exotic example that we
> would want to avoid, but this is not a good enough justification for
> this rule.
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>   * I think we saw a good example that !! was used in a recent review
>     thread, and the idea to remove this rule was floated back then,
>     but without following through.

Yes, its come up a couple of times recently, thanks for putting a patch 
together.

Phillip

>   Documentation/CodingGuidelines | 4 ----
>   1 file changed, 4 deletions(-)
> 
> diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines
> index 3c8d6c7dd3..4bfa615bac 100644
> --- c/Documentation/CodingGuidelines
> +++ w/Documentation/CodingGuidelines
> @@ -522,10 +522,6 @@ For C programs:
>   	    that_is_used_in + a_very_long_expression) {
>   		...
>   
> - - Some clever tricks, like using the !! operator with arithmetic
> -   constructs, can be extremely confusing to others.  Avoid them,
> -   unless there is a compelling reason to use them.
> -
>    - Use the API.  No, really.  We have a strbuf (variable length
>      string), several arrays with the ALLOC_GROW() macro, a
>      string_list for sorted string lists, a hash map (mapping struct


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] CodingGuidelines: !! is not all that exotic
  2026-11-18 18:31 [PATCH] CodingGuidelines: !! is not all that exotic Junio C Hamano
  2026-11-19 10:44 ` Phillip Wood
@ 2026-11-19 15:15 ` Kristoffer Haugsbakk
  1 sibling, 0 replies; 3+ messages in thread
From: Kristoffer Haugsbakk @ 2026-11-19 15:15 UTC (permalink / raw)
  To: Junio C Hamano, git; +Cc: Phillip Wood

On Wed, Nov 18, 2026, at 19:31, Junio C Hamano wrote:
> Remove the clause against "clever tricks" that cites !!value that is
> a standard technique to normalize a value to 0/1 boolean.  We could
> resurrect it if we can come up with a truly exotic example that we
> would want to avoid, but this is not a good enough justification for
> this rule.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  * I think we saw a good example that !! was used in a recent review
>    thread, and the idea to remove this rule was floated back then,
>    but without following through.
>
>  Documentation/CodingGuidelines | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines
> index 3c8d6c7dd3..4bfa615bac 100644
> --- c/Documentation/CodingGuidelines
> +++ w/Documentation/CodingGuidelines
> @@ -522,10 +522,6 @@ For C programs:
>  	    that_is_used_in + a_very_long_expression) {
>  		...
>
> - - Some clever tricks, like using the !! operator with arithmetic
> -   constructs, can be extremely confusing to others.  Avoid them,
> -   unless there is a compelling reason to use them.
> -
>   - Use the API.  No, really.  We have a strbuf (variable length
>     string), several arrays with the ALLOC_GROW() macro, a
>     string_list for sorted string lists, a hash map (mapping struct

I wondered why this was added in the first place. But this dates back to
6d0618a8 (Add Documentation/CodingGuidelines, 2007-11-08). So it was
there from the start. And you objected to it on the first version:

https://lore.kernel.org/git/7v640ega5q.fsf@gitster.siamese.dyndns.org/

JC> I actually think (!!var) idiom is already established in our
JC> codebase.

Andreas Ericsson replied and emphasized *arithmetic expressions*, which
I guess means that it is not just a single expression normalized to a
boolean.

AE> Not very widely for arithmetic expressions though. I believe this
AE> alludes to the (!!a + !!b + !!c) idiom used earlier, where it's not
AE> exactly clear *why* a, b and c can be > 1 if != 0 is the only thing
AE> we care about.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-19 15:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 18:31 [PATCH] CodingGuidelines: !! is not all that exotic Junio C Hamano
2026-11-19 10:44 ` Phillip Wood
2026-11-19 15:15 ` Kristoffer Haugsbakk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox