git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/6] give "nbuf" strbuf a more meaningful name
Date: Sun, 31 Jan 2016 13:01:02 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1601311300400.2964@virtualbox> (raw)
In-Reply-To: <20160131115947.GA5438@sigill.intra.peff.net>

Hi Peff,

On Sun, 31 Jan 2016, Jeff King wrote:

> On Sun, Jan 31, 2016 at 12:54:29PM +0100, Johannes Schindelin wrote:
> 
> > On Sun, 31 Jan 2016, Jeff King wrote:
> > 
> > > > It's a shame that we can't just factor out this common
> > > > code, but I don't think it's quite long enough to merit
> > > > the boilerplate. The interesting part of each function
> > > > happens inside the loop. If C had lambdas, we could do
> > > > something like:
> > > > 
> > > >   foreach_path_from(stdin, nul_term_line) {
> > > >         /* now do something interesting with "buf"
> > > >            and some other local variables */
> > > >   }
> > 
> > Technically, we do not have to do lambdas for that paradigm, we could
> > introduce a new data type and a reader, i.e. something like this:
> > [...]
> > And then the repeated code could be replaced by something like this:
> > 
> > 	struct path_reader path_reader = PATH_READER_INIT;
> > 
> > 	while (read_next_path(&reader, stdin, 1)) {
> > 		... [work with reader->path.buf] ...
> > 	}
> > 
> > 	cleanup_path_reader();
> 
> Yeah, you're right. I was thinking of lifting the loop completely out of
> the call-sites, but simplifying it to a single line loop condition is
> just as good.
> 
> I still think this crosses my line of "too much boilerplate to be worth
> it", though.

Oh, I totally agree. Just wanted to point out that there are other
options.

Ciao,
Dscho

  reply	other threads:[~2016-01-31 12:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-31 11:22 [PATCH 0/6] post-strbuf_getline cleanups Jeff King
2016-01-31 11:25 ` [PATCH 1/6] give "nbuf" strbuf a more meaningful name Jeff King
2016-01-31 11:54   ` Johannes Schindelin
2016-01-31 11:59     ` Jeff King
2016-01-31 12:01       ` Johannes Schindelin [this message]
2016-01-31 11:25 ` [PATCH 2/6] checkout-index: simplify "-z" option parsing Jeff King
2016-01-31 11:26 ` [PATCH 3/6] checkout-index: handle "--no-prefix" option Jeff King
2016-01-31 11:29 ` [PATCH 4/6] checkout-index: handle "--no-index" option Jeff King
2016-02-01  2:25   ` Junio C Hamano
2016-02-01  3:22     ` Jeff King
2016-01-31 11:30 ` [PATCH 5/6] checkout-index: disallow "--no-stage" option Jeff King
2016-02-01  2:18   ` Junio C Hamano
2016-02-01  3:18     ` Jeff King
2016-01-31 11:35 ` [PATCH 6/6] apply, ls-files: simplify "-z" parsing Jeff King
2016-01-31 11:59   ` Johannes Schindelin
2016-02-01 21:47   ` Junio C Hamano
2016-02-01 22:52     ` Junio C Hamano
2016-02-02  5:29       ` Jeff King
2016-02-01  2:14 ` [PATCH 0/6] post-strbuf_getline cleanups 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=alpine.DEB.2.20.1601311300400.2964@virtualbox \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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).