From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: Shourya Shukla <shouryashukla.oo@gmail.com>,
chrisitan.couder@gmail.com, Denton Liu <liu.denton@gmail.com>,
git <git@vger.kernel.org>
Subject: Re* [PATCH v4] submodule: port subcommand 'set-url' from shell to C
Date: Fri, 08 May 2020 08:18:32 -0700 [thread overview]
Message-ID: <xmqq8si21mlz.fsf_-_@gitster.c.googlers.com> (raw)
In-Reply-To: <CAP8UFD0=_8D8hkT5VVPV_F++dr131bkjby357fA+QfhQxktcMg@mail.gmail.com> (Christian Couder's message of "Fri, 8 May 2020 08:18:57 +0200")
Christian Couder <christian.couder@gmail.com> writes:
> On Fri, May 8, 2020 at 7:51 AM Shourya Shukla
> <shouryashukla.oo@gmail.com> wrote:
>>
>> On 06/05 10:08, Junio C Hamano wrote:
>
>> > Specifically, I would write "!path", not "path == NULL". I thought
>> > a rule for that is in the CodingGuidelines (I didn't double check,
>> > though).
>>
>> I could not find a rule like that in the CodingGuidelines.
>> Should I add it?
>> https://github.com/git/git/blob/master/Documentation/CodingGuidelines
>
> Sure.
I'd rather not see too many unrelated things piled up on Shourya's
plate. Without guidance, the new entry we'll see would be only
about comparing with NULL, and we'd need to spend review cycles
correcting that, too.
How about something like this, perhaps?
-- >8 --
CodingGuidelines: do not ==/!= compare with 0/NULL
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Documentation/CodingGuidelines | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 390ceece52..41a89dd845 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -236,6 +236,19 @@ For C programs:
while( condition )
func (bar+1);
+ - Do not explicitly compare an integral value with constant 0 or a
+ pointer value with constant NULL for equality; just say !value
+ instead. To validate a counted array at ptr that has cnt elements
+ in it, write:
+
+ if (!ptr || !cnt)
+ BUG("array should not be empty at this point");
+
+ and not:
+
+ if (ptr == NULL || cnt == 0);
+ BUG("array should not be empty at this point");
+
- We avoid using braces unnecessarily. I.e.
if (bla) {
next prev parent reply other threads:[~2020-05-08 15:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-06 7:37 [PATCH v4] submodule: port subcommand 'set-url' from shell to C Shourya Shukla
2020-05-06 8:09 ` Christian Couder
2020-05-06 16:31 ` Shourya Shukla
2020-05-06 17:16 ` Junio C Hamano
2020-05-06 17:12 ` Junio C Hamano
2020-05-06 18:12 ` Shourya Shukla
2020-05-06 18:22 ` Junio C Hamano
2020-05-07 4:40 ` Shourya Shukla
2020-05-07 5:08 ` Junio C Hamano
2020-05-08 5:47 ` Shourya Shukla
2020-05-08 6:18 ` Christian Couder
2020-05-08 15:18 ` Junio C Hamano [this message]
2020-05-08 15:38 ` Re* " Eric Sunshine
2020-05-08 15:57 ` Junio C Hamano
2020-05-08 16:13 ` Eric Sunshine
2020-05-08 16:38 ` Junio C Hamano
2020-05-08 17:51 ` Eric Sunshine
2020-05-08 6:21 ` [PATCH v5] " Shourya Shukla
2020-05-08 6:30 ` Denton Liu
2020-05-08 16:13 ` Junio C Hamano
2020-05-08 16:17 ` Junio C Hamano
2020-05-08 16:18 ` [PATCH v6] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq8si21mlz.fsf_-_@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=chrisitan.couder@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=liu.denton@gmail.com \
--cc=shouryashukla.oo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).