From: Stefan Beller <sbeller@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Jeff King <peff@peff.net>, Brandon Williams <bmwill@google.com>,
"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [RFC] clang-format: outline the git project's coding style
Date: Wed, 9 Aug 2017 15:53:17 -0700 [thread overview]
Message-ID: <CAGZ79kYEyebHxFO++u5RkPBj16xx5nMcahBPxra4xWUfMrXydA@mail.gmail.com> (raw)
In-Reply-To: <87y3qsg7ni.fsf@gmail.com>
On Wed, Aug 9, 2017 at 7:03 AM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
>
> On Wed, Aug 09 2017, Jeff King jotted:
>
>> On Mon, Aug 07, 2017 at 06:25:54PM -0700, Brandon Williams wrote:
>>
>>> I'm sure this sort of thing comes up every so often on the list but back at
>>> git-merge I mentioned how it would be nice to not have to worry about style
>>> when reviewing patches as that is something mechanical and best left to a
>>> machine (for the most part). I saw that 'clang-format' was brought up on the
>>> list once before a couple years ago
>>> (https://public-inbox.org/git/20150121220903.GA10267@peff.net/) but nothing
>>> really came of it. I spent a little bit of time combing through the various
>>> options and came up with this config based on the general style of our code
>>> base. The big issue though is that our code base isn't consistent so try as
>>> you might you wont be able to come up with a config which matches everything we
>>> do (mostly due to the inconsistencies in our code base).
>>
>> Right, the reason I stopped pursuing it was that I couldn't find a way
>> to have it make suggestions for new code without nagging about existing
>> code. If we were to aggressively reformat to match the tool for existing
>> code, that would help. But I'm a bit worried that there would always be
>> suggestions from the tool that we don't agree with (i.e., where the
>> guiding principle is "do what is readable").
We may have different opinions on what is readable/beautiful code.
If we were to follow a mutual agreed style that is produced by a tool,
we could use clean/smudge filters with different settings each.
But I think we'd rather want to find the closest approximation to our
current style first.
>> I dunno. I guess "go fmt" people decided to just treat the tool's output
>> as the One True Way. I haven't written enough Go to have an opinion
>> myself, but it seems to at least work for them.
>
> (I have no opinion either way on whether this clang formatting this is a
> good idea or not)
I think it is actually beneficial as it is one less thing to worry about
as a contributor. Maybe compare it to programming language that
has garbage collection built in, which is also a feature to allow the
contributor to focus on "what is important". (style is not, all it can do
is hold back progress by too much nitpicking IMHO)
>> What does the tooling look like these days for just adjusting lines
>> touched by a given patch?
$ clang-format --help
USAGE: clang-format [options] [<file> ...]
..
-i - Inplace edit <file>s, if specified..
-lines=<string> - <start line>:<end line> - format a range of
lines (both 1-based).
Multiple ranges can be formatted by specifying
several -lines arguments.
Can't be used with -offset and -length.
Can only be used with one input file.
..
I would think based on these options, a pre commit hook can be
written that formats precisely the touched lines of code of each file.
>
> Presumably even if it sucked we could easily write a "./git-fmt-check.sh
> <file>" script to do it which would do the following:
>
> 1. Check out the master branch
> 2. Apply code formatting to entire project (or just the files you
> changed)
> 3. Commit that on a throwaway branch
> 4. Switch back to your WIP branch
> 5. See if it would merge cleanly with the throwaway code formatting
> branch (I forget the actual 'not a real merge but check' command to
> do this, but it exists).
>
> If there were any reported conflicts presumably the new code you're
> adding is violating the coding standards laid out in this file. If not
> you're good.
This approach certainly works, but it *adds* one more step to what
a contributor may need to do before sending a patch. I think the intention
with a codified style is to *remove* a step (as a machine will do it for you).
next prev parent reply other threads:[~2017-08-09 22:53 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 1:25 [RFC] clang-format: outline the git project's coding style Brandon Williams
2017-08-08 12:05 ` Johannes Schindelin
2017-08-08 17:40 ` Stefan Beller
2017-08-08 18:23 ` Brandon Williams
2017-08-09 22:33 ` Johannes Schindelin
2017-08-09 22:42 ` Stefan Beller
2017-08-10 9:38 ` Johannes Schindelin
2017-08-10 16:41 ` Junio C Hamano
2017-08-10 17:15 ` Brandon Williams
2017-08-10 17:28 ` Junio C Hamano
2017-08-10 21:30 ` Brandon Williams
2017-08-11 20:06 ` Ben Peart
2017-08-14 15:52 ` Johannes Schindelin
2017-09-28 11:41 ` Johannes Schindelin
2017-09-28 17:16 ` Brandon Williams
2017-08-08 17:45 ` Junio C Hamano
2017-08-08 18:03 ` Brandon Williams
2017-08-08 18:25 ` Junio C Hamano
2017-08-09 7:05 ` Junio C Hamano
2017-08-11 17:49 ` Brandon Williams
2017-08-11 19:00 ` Junio C Hamano
2017-08-09 13:01 ` Jeff King
2017-08-09 14:03 ` Ævar Arnfjörð Bjarmason
2017-08-09 22:53 ` Stefan Beller [this message]
2017-08-09 23:11 ` Stefan Beller
2017-08-11 17:52 ` Brandon Williams
2017-08-11 21:18 ` Jeff King
2017-08-12 4:39 ` Junio C Hamano
2017-08-13 4:41 ` Jeff King
2017-08-13 16:14 ` Ramsay Jones
2017-08-13 16:36 ` Ramsay Jones
2017-08-13 17:33 ` Junio C Hamano
2017-08-13 19:17 ` Ramsay Jones
2017-08-09 23:19 ` Jeff King
2017-08-15 0:40 ` brian m. carlson
2017-08-15 1:03 ` Jonathan Nieder
2017-08-14 21:30 ` [PATCH v2 0/2] clang-format Brandon Williams
2017-08-14 21:30 ` [PATCH v2 1/2] clang-format: outline the git project's coding style Brandon Williams
2017-08-14 22:02 ` Stefan Beller
2017-08-15 13:56 ` Ben Peart
2017-08-15 17:37 ` Brandon Williams
2017-08-14 22:48 ` Jeff King
2017-08-14 22:51 ` Jeff King
2017-08-14 22:54 ` Brandon Williams
2017-08-14 23:01 ` Jeff King
2017-08-16 12:18 ` Johannes Schindelin
2017-08-15 14:28 ` Ben Peart
2017-08-15 17:34 ` Brandon Williams
2017-08-15 17:41 ` Stefan Beller
2017-08-14 21:30 ` [PATCH v2 2/2] Makefile: add style build rule Brandon Williams
2017-08-14 21:53 ` Stefan Beller
2017-08-14 22:25 ` Junio C Hamano
2017-08-14 22:28 ` Stefan Beller
2017-08-14 22:57 ` Jeff King
2017-08-14 23:29 ` Junio C Hamano
2017-08-14 23:47 ` Junio C Hamano
2017-08-15 0:05 ` Brandon Williams
2017-08-15 1:52 ` Jeff King
2017-08-14 21:32 ` [PATCH v2 0/2] clang-format Brandon Williams
2017-08-14 23:06 ` Jeff King
2017-08-14 23:15 ` Stefan Beller
2017-08-15 1:47 ` Jeff King
2017-08-15 3:03 ` Junio C Hamano
2017-08-15 3:38 ` Jeff King
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=CAGZ79kYEyebHxFO++u5RkPBj16xx5nMcahBPxra4xWUfMrXydA@mail.gmail.com \
--to=sbeller@google.com \
--cc=avarab@gmail.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--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.
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).