Re: [PATCH 1/6] give "nbuf" strbuf a more meaningful name
- From
Jeff King <peff@peff.net>
- Date
- Jan 31, 2016, 11:59 UTC
- Message-ID
- <20160131115947.GA5438@sigill.intra.peff.net>
- In-Reply-To
- <alpine.DEB.2.20.1601311245170.2964@virtualbox>
On Sun, Jan 31, 2016 at 12:54:29PM +0100, Johannes Schindelin wrote:
Show 27 quoted lines
> Hi Peff,
>
> 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.
-Peff