From: Dmitry Kakurin <dmitry.kakurin@gmail.com>
To: "Git" <git@vger.kernel.org>
Subject: C++ *for Git*
Date: Sat, 22 Sep 2007 03:42:00 -0700 [thread overview]
Message-ID: <ABE0ABE82AE84593A2B71B0281F4C814@ntdev.corp.microsoft.com> (raw)
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 reply other threads:[~2007-09-22 10:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-22 10:42 Dmitry Kakurin [this message]
2007-09-22 11:11 ` C++ *for Git* David Kastrup
2007-09-22 12:48 ` Johannes Schindelin
2007-09-22 15:23 ` Marco Costalba
2007-09-23 4:54 ` Dmitry Kakurin
2007-09-22 15:15 ` Kyle Rose
2007-09-22 18:08 ` Miles Bader
2007-09-22 18:25 ` [OT] " Kyle Rose
2007-09-22 19:11 ` David Kastrup
2007-09-22 22:50 ` Alex Unleashed
2007-09-23 2:09 ` Frank Lichtenheld
2007-09-23 6:25 ` David Brown
2007-09-23 7:23 ` David Kastrup
2007-09-23 9:29 ` Marco Costalba
2007-09-23 9:42 ` David Kastrup
2007-09-23 9:50 ` Marco Costalba
2007-09-23 10:45 ` Pierre Habouzit
2007-09-23 13:42 ` Marco Costalba
2007-09-23 14:23 ` Nicolas Pitre
2007-09-23 14:45 ` Marco Costalba
2007-09-23 14:37 ` David Kastrup
2007-09-23 15:15 ` Marco Costalba
2007-09-23 17:49 ` Paul Franz
2007-09-23 16:54 ` Linus Torvalds
2007-09-23 18:05 ` Marco Costalba
2007-09-23 18:30 ` David Kastrup
2007-09-23 18:43 ` Marco Costalba
2007-09-23 19:11 ` David Kastrup
2007-09-23 21:22 ` Dmitry Potapov
2007-09-23 21:31 ` David Kastrup
2007-09-23 23:10 ` Robin Rosenberg
2007-09-23 22:25 ` Reece Dunn
2007-09-24 10:46 ` Dmitry Potapov
2007-09-22 22:24 ` Martin Langhoff
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ABE0ABE82AE84593A2B71B0281F4C814@ntdev.corp.microsoft.com \
--to=dmitry.kakurin@gmail.com \
--cc=git@vger.kernel.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).