git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>, Jeff King <peff@peff.net>,
	Chris Torek <chris.torek@gmail.com>
Subject: Re: [PATCH] pkt-line: extract out PACKET_HEADER_SIZE
Date: Sat, 13 Jun 2020 10:39:31 -0400	[thread overview]
Message-ID: <20200613143931.GA730181@generichostname> (raw)
In-Reply-To: <20200613142306.GA4680@danh.dev>

On Sat, Jun 13, 2020 at 09:23:06PM +0700, Đoàn Trần Công Danh wrote:
> > diff --git a/pkt-line.c b/pkt-line.c
> > index 8f9bc68ee2..245a56712f 100644
> > --- a/pkt-line.c
> > +++ b/pkt-line.c
> > @@ -87,43 +87,43 @@ static void packet_trace(const char *buf, unsigned int len, int write)
> >   */
> >  void packet_flush(int fd)
> >  {
> > -	packet_trace("0000", 4, 1);
> > -	if (write_in_full(fd, "0000", 4) < 0)
> > +	packet_trace("0000", PACKET_HEADER_SIZE, 1);
> > +	if (write_in_full(fd, "0000", PACKET_HEADER_SIZE) < 0)
> 
> I think the magic number 4 is easier to follow than some macro
> PACKET_HEADER_SIZE defined elsewhere. Because reader may judge that is
> the size of "0000"
> 
> How about (this ugly code):
> 
> 	packet_trace("0000", sizeof "0000" - 1, 1);
> 	if (write_in_full(fd, "0000", sizeof "0000" - 1) < 0)

Chris Torek mentioned something similar off-list:
> This seems sensible, but at the same time, the string literals must
> have the right size.  For instance:
> 
[...the diff above...]
> 
> So if you're going to do this, it might be a good idea to replace
> the string literals "0000", "0001", etc, with defined values as well.

Between the two suggested approaches, with your approach, it's
immediately obvious what the values of the packets are but, on the other
hand, with Chris's approach, we can consolidate the "magic" string
literals together into a definition in a single-place.

In this case, the strings don't seem too magical and I think that the
people on this list are generally against over-abstracting and would
consider it more readable to leave the literals in place. (If this were
my own project, I'd take Chris's approach, though, since I try to avoid
bare literals like the plague.)

  reply	other threads:[~2020-06-13 14:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-13 13:43 [PATCH] pkt-line: extract out PACKET_HEADER_SIZE Denton Liu
2020-06-13 14:23 ` Đoàn Trần Công Danh
2020-06-13 14:39   ` Denton Liu [this message]
2020-06-13 16:51   ` Junio C Hamano
2020-06-14 18:24     ` Junio C Hamano
2020-06-14  7:31 ` Denton Liu
2020-06-14  7:31 ` [PATCH v2 0/3] pkt-line: war on magical `4` literal Denton Liu
2020-06-14  7:31   ` [PATCH v2 1/3] remote-curl: use strlen() instead of magic numbers Denton Liu
2020-06-14  7:31   ` [PATCH v2 2/3] pkt-line: use string versions of functions Denton Liu
2020-06-14  8:31     ` Đoàn Trần Công Danh
2020-06-14  9:07       ` [PATCH v2] " Denton Liu
2020-06-14 21:35         ` Junio C Hamano
2020-06-14 22:28           ` Denton Liu
2020-06-15 12:32         ` Đoàn Trần Công Danh
2020-06-14  7:32   ` [PATCH v2 3/3] pkt-line: extract out PACKET_HEADER_SIZE Denton Liu
2020-06-14 21:32   ` [PATCH v2 0/3] pkt-line: war on magical `4` literal Junio C Hamano
2020-06-23 17:55   ` [PATCH v3 " Denton Liu
2020-06-23 17:55     ` [PATCH v3 1/3] remote-curl: use strlen() instead of magic numbers Denton Liu
2020-06-23 18:54       ` Jeff King
2020-06-23 19:39         ` Junio C Hamano
2020-06-23 17:55     ` [PATCH v3 2/3] pkt-line: use string versions of functions Denton Liu
2020-06-23 19:11       ` Jeff King
2020-06-23 17:55     ` [PATCH v3 3/3] pkt-line: extract out PACKET_HEADER_SIZE Denton Liu

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=20200613143931.GA730181@generichostname \
    --to=liu.denton@gmail.com \
    --cc=chris.torek@gmail.com \
    --cc=congdanhqx@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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).