git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/6] give "nbuf" strbuf a more meaningful name

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 31, 2016, 12:01 UTC
Message-ID
<alpine.DEB.2.20.1601311300400.2964@virtualbox>
In-Reply-To
<20160131115947.GA5438@sigill.intra.peff.net>
Hi Peff,
On Sun, 31 Jan 2016, Jeff King wrote:
Show 34 quoted lines
> 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

Previous: Jeff KingNext: Jeff King
Message 5 of 19 in “post-strbuf_getline cleanups”
  1. 0/6 post-strbuf_getline cleanupsJeff King, Jan 31, 2016
  2. 1/6 give "nbuf" strbuf a more meaningful nameJeff King, Jan 31, 2016
  3. Johannes SchindelinJan 31, 2016
  4. Jeff KingJan 31, 2016
  5. Johannes SchindelinJan 31, 2016
  6. 2/6 checkout-index: simplify "-z" option parsingJeff King, Jan 31, 2016
  7. 3/6 checkout-index: handle "--no-prefix" optionJeff King, Jan 31, 2016
  8. 4/6 checkout-index: handle "--no-index" optionJeff King, Jan 31, 2016
  9. Junio C HamanoFeb 1, 2016
  10. Jeff KingFeb 1, 2016
  11. 5/6 checkout-index: disallow "--no-stage" optionJeff King, Jan 31, 2016
  12. Junio C HamanoFeb 1, 2016
  13. Jeff KingFeb 1, 2016
  14. 6/6 apply, ls-files: simplify "-z" parsingJeff King, Jan 31, 2016
  15. Johannes SchindelinJan 31, 2016
  16. Junio C HamanoFeb 1, 2016
  17. Junio C HamanoFeb 1, 2016
  18. Jeff KingFeb 2, 2016
  19. Junio C HamanoFeb 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.