[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Enforcing Code Style

From: Kevin Grover <kevin_at_kevingrover.net>
Date: Fri, 22 Aug 2008 12:13:31 -0700

On Fri, Aug 22, 2008 at 3:02 AM, Tom Browder <tom.browder_at_gmail.com> wrote:

> I think this has been discussed before, but I would appreciate any
> ideas on how to minimize formatting changes from multiple developers
> using different operating systems and different editors (and
> settings).
> We have inherited old code with GROSS formatting and are cleaning up
> the worst as we go. But for the future, when we add more developers,
> we would like to preserve what we have improved.
> I am thinking of periodically running a script that filters all source
> and header files (C++) through a beautifier like bcpp.
> Thanks.
> -Tom
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
> For additional commands, e-mail: users-help_at_subversion.tigris.org
I would reformat all code upfront, in one step, and commit it with a comment
along the lines of "Reformated with 'codeformat ARGS and OPTIONS'". If
people reformat as they change things, it becomes impossible to tell what
really changed. E.g. the actual code changed get eclipsed by the
reformatting changes.

For day-to-day development, you can either _encourage_ developers to use the
correct style in the future: this will be mostly automatic if your tools
(editor) format the way you want.

And/or, you can add a pre-commit hook script that looks at each file in a
commit: for each type to which your coding standards apply (i.e. source
files, not text or other files), you filter it through the re-formatter (to
a temp copy) and then compare that to the original (diff). If they are not
the same, the script dies with an error string "Source file XXXX is not in
the correct coding style:" (you could also append the diff text from the
compare). If you have a tool that just checks for coding style, you can
also use that and die if it complains.

This forces users to use tools that keep code correctly formatted, or to run
it through the filter before commiting.

The second approach can be a little draconian.

As an FYI, another nice reformatter is astyle (Artistic Style). I like it
because it's standalone, configurable, and runs everywhere.

- Kevin
Received on 2008-08-22 21:13:50 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.