{"thread":{"id":"66874","subject":"[PATCH] CodingGuidelines: !! is not all that exotic","startedAt":"2026-11-18T18:31:00Z","lastAt":"2026-11-19T15:15:34Z","messageCount":3,"participants":["Junio C Hamano","Phillip Wood","Kristoffer Haugsbakk"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558733","messageId":"xmqq33sy6lgb.fsf@gitster.g","threadId":"66874","inReplyTo":null,"subject":"[PATCH] CodingGuidelines: !! is not all that exotic","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T18:31:00Z","receivedAt":"2026-11-18T18:31:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Remove the clause against \"clever tricks\" that cites !!value that is\na standard technique to normalize a value to 0/1 boolean.  We could\nresurrect it if we can come up with a truly exotic example that we\nwould want to avoid, but this is not a good enough justification for\nthis rule.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n * I think we saw a good example that !! was used in a recent review\n   thread, and the idea to remove this rule was floated back then,\n   but without following through.\n\n Documentation/CodingGuidelines | 4 ----\n 1 file changed, 4 deletions(-)\n\ndiff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines\nindex 3c8d6c7dd3..4bfa615bac 100644\n--- c/Documentation/CodingGuidelines\n+++ w/Documentation/CodingGuidelines\n@@ -522,10 +522,6 @@ For C programs:\n \t    that_is_used_in + a_very_long_expression) {\n \t\t...\n \n- - Some clever tricks, like using the !! operator with arithmetic\n-   constructs, can be extremely confusing to others.  Avoid them,\n-   unless there is a compelling reason to use them.\n-\n  - Use the API.  No, really.  We have a strbuf (variable length\n    string), several arrays with the ALLOC_GROW() macro, a\n    string_list for sorted string lists, a hash map (mapping struct\n\n"},{"id":"558816","messageId":"ebcf98af-a633-4e51-97f0-099084beeef5@gmail.com","threadId":"66874","inReplyTo":"xmqq33sy6lgb.fsf@gitster.g","subject":"Re: [PATCH] CodingGuidelines: !! is not all that exotic","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-11-19T10:44:12Z","receivedAt":"2026-11-19T10:44:12Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Junio\n\nOn 18/11/2026 18:31, Junio C Hamano wrote:\n> Remove the clause against \"clever tricks\" that cites !!value that is\n> a standard technique to normalize a value to 0/1 boolean.  We could\n> resurrect it if we can come up with a truly exotic example that we\n> would want to avoid, but this is not a good enough justification for\n> this rule.\n> > Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>   * I think we saw a good example that !! was used in a recent review\n>     thread, and the idea to remove this rule was floated back then,\n>     but without following through.\n\nYes, its come up a couple of times recently, thanks for putting a patch together.\n\nPhillip\n\n>   Documentation/CodingGuidelines | 4 ----\n>   1 file changed, 4 deletions(-)\n> > diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines\n> index 3c8d6c7dd3..4bfa615bac 100644\n> --- c/Documentation/CodingGuidelines\n> +++ w/Documentation/CodingGuidelines\n> @@ -522,10 +522,6 @@ For C programs:\n>   \t    that_is_used_in + a_very_long_expression) {\n>   \t\t...\n>   > - - Some clever tricks, like using the !! operator with arithmetic\n> -   constructs, can be extremely confusing to others.  Avoid them,\n> -   unless there is a compelling reason to use them.\n> -\n>    - Use the API.  No, really.  We have a strbuf (variable length\n>      string), several arrays with the ALLOC_GROW() macro, a\n>      string_list for sorted string lists, a hash map (mapping struct\n\n\n"},{"id":"558853","messageId":"b0e1d692-0be0-4453-97f2-c6581630b9e9@app.fastmail.com","threadId":"66874","inReplyTo":"xmqq33sy6lgb.fsf@gitster.g","subject":"Re: [PATCH] CodingGuidelines: !! is not all that exotic","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-11-19T15:15:34Z","receivedAt":"2026-11-19T15:15:34Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Wed, Nov 18, 2026, at 19:31, Junio C Hamano wrote:\n> Remove the clause against \"clever tricks\" that cites !!value that is\n> a standard technique to normalize a value to 0/1 boolean.  We could\n> resurrect it if we can come up with a truly exotic example that we\n> would want to avoid, but this is not a good enough justification for\n> this rule.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  * I think we saw a good example that !! was used in a recent review\n>    thread, and the idea to remove this rule was floated back then,\n>    but without following through.\n>\n>  Documentation/CodingGuidelines | 4 ----\n>  1 file changed, 4 deletions(-)\n>\n> diff --git c/Documentation/CodingGuidelines w/Documentation/CodingGuidelines\n> index 3c8d6c7dd3..4bfa615bac 100644\n> --- c/Documentation/CodingGuidelines\n> +++ w/Documentation/CodingGuidelines\n> @@ -522,10 +522,6 @@ For C programs:\n>  \t    that_is_used_in + a_very_long_expression) {\n>  \t\t...\n>\n> - - Some clever tricks, like using the !! operator with arithmetic\n> -   constructs, can be extremely confusing to others.  Avoid them,\n> -   unless there is a compelling reason to use them.\n> -\n>   - Use the API.  No, really.  We have a strbuf (variable length\n>     string), several arrays with the ALLOC_GROW() macro, a\n>     string_list for sorted string lists, a hash map (mapping struct\n\nI wondered why this was added in the first place. But this dates back to\n6d0618a8 (Add Documentation/CodingGuidelines, 2007-11-08). So it was\nthere from the start. And you objected to it on the first version:\n\nhttps://lore.kernel.org/git/7v640ega5q.fsf@gitster.siamese.dyndns.org/\n\nJC> I actually think (!!var) idiom is already established in our\nJC> codebase.\n\nAndreas Ericsson replied and emphasized *arithmetic expressions*, which\nI guess means that it is not just a single expression normalized to a\nboolean.\n\nAE> Not very widely for arithmetic expressions though. I believe this\nAE> alludes to the (!!a + !!b + !!c) idiom used earlier, where it's not\nAE> exactly clear *why* a, b and c can be > 1 if != 0 is the only thing\nAE> we care about.\n\n"}]}