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

C++ *for Git*

From
DKDmitry Kakurin <dmitry.kakurin@gmail.com>
Date
Sep 22, 2007, 10:42 UTC
Message-ID
<ABE0ABE82AE84593A2B71B0281F4C814@ntdev.corp.microsoft.com>

We've had this theoretical (and IMHO pointless) discussion C vs. C++ *in general*. In no way I want to restart it. But *very specifically*, and *for Git*: We already have strbuf "class" to do string/buffer manipulations. Kudos to Pierre Habouzit for doing the refactoring work! Now, what I fail to understand is how this:

static void write_global_extended_header(const unsigned char *sha1)
{
    struct strbuf ext_header;
    strbuf_init(&ext_header, 0);
    strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
    write_entry(NULL, NULL, 0, ext_header.buf, ext_header.len);
    strbuf_release(&ext_header);
}
is better than this:
static void write_global_extended_header(const unsigned char *sha1)
{
    strbuf ext_header;
    ext_header.append_ext_header("comment", sha1_to_hex(sha1), 40);
    write_entry(NULL, NULL, 0, ext_header.buf, ext_header.len);
}
?
Note, there is no Boost/multiple inheritance/template 
metaprogramming/std::string/whatever-else-scares-you-in-C++ in the second 
piece of code.
Just a very straight-forward usage of only 3 C++ features:
1. Constructors
2. Destructors
3. Better syntax (ext_header.append_ext_header vs. 
strbuf_append_ext_header(&ext_header, )

The generated code will be exactly the same. Yet the source code becomes more readable and MUCH less error prone. How is this not a win?

One (sensible) argument that I've heard in the previous discussion was: you let a little bit of C++ in and then it gets more and more complex and the code quality decreases. This problem is solved by having "quality gates". Again, *for Git* these quality gates already exist: only few people have "commit access". If/when somebody tries to be too fancy, what stops Junio from replying "we don't use Library-X/C++-feature-Y in Git, please change your code and resubmit" and throwing that fix away? Nothing.

- Dmitry
Next: David Kastrup
Message 1 of 34 in “C++ *for Git*”
  1. Dmitry KakurinSep 22, 2007
  2. David KastrupSep 22, 2007
  3. Johannes SchindelinSep 22, 2007
  4. Marco CostalbaSep 22, 2007
  5. Dmitry KakurinSep 23, 2007
  6. Kyle RoseSep 22, 2007
  7. Miles BaderSep 22, 2007
  8. [OT] Re: C++ *for Git*Kyle Rose, Sep 22, 2007
  9. David KastrupSep 22, 2007
  10. Alex UnleashedSep 22, 2007
  11. Frank LichtenheldSep 23, 2007
  12. David BrownSep 23, 2007
  13. David KastrupSep 23, 2007
  14. Marco CostalbaSep 23, 2007
  15. David KastrupSep 23, 2007
  16. Marco CostalbaSep 23, 2007
  17. Pierre HabouzitSep 23, 2007
  18. Marco CostalbaSep 23, 2007
  19. Nicolas PitreSep 23, 2007
  20. Marco CostalbaSep 23, 2007
  21. David KastrupSep 23, 2007
  22. Marco CostalbaSep 23, 2007
  23. Paul FranzSep 23, 2007
  24. Linus TorvaldsSep 23, 2007
  25. Marco CostalbaSep 23, 2007
  26. David KastrupSep 23, 2007
  27. Marco CostalbaSep 23, 2007
  28. David KastrupSep 23, 2007
  29. Dmitry PotapovSep 23, 2007
  30. David KastrupSep 23, 2007
  31. Robin RosenbergSep 23, 2007
  32. Reece DunnSep 23, 2007
  33. Dmitry PotapovSep 24, 2007
  34. Martin LanghoffSep 22, 2007

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.