Automatic code formatting

Guus Sliepen guus at tinc-vpn.org
Tue Oct 3 21:46:32 CEST 2017


A heads up: very soon the code base of tinc will be reformatted using
Artistic Style. I've already pushed the .astylerc to the master and 1.1
branches, including a Makefile rule so you can run "make astyle" from
the top directory and have all source files automatically formatted.

The .astylerc reflects the current code style of tinc, but with the
following important changes:

- Single-line if and else statements will now always have braces. I
  would have preferred to keep them without braces in if and if+else
  statements where all clauses consist of one line, but Artistic Style
  does not support that. On the upside, this makes the style more
  consistent, and makes it easier to add statements to a single-line if
  or else clause.

- Switch statements will have their case statements indented at the same
  level as the switch.

- Empty lines will be forced above and below control blocks (ie, if
  statements, for loops and so on).

I'll also run sed on the codebase to add parentheses around the argument
of sizeof operators, since code formatters otherwise turn "sizeof *foo"
into "sizeof * foo".

Formatting will affect a large part of the code base, so if you have any
branches that you want merged with the official repository, now would be
a good time to tell me if you want to avoid with any conflicts when
rebasing your work after the code formatting changes.

The rationale behind using automated code formatting is that it improves
the visual consistency of the code, without having to think too much
about it. It also allows you to edit the code in whatever way you like,
and just run the formatter on it before you send a patch or submit a
pull request.

I chose the Artistic Style formatter because it's a bit smarter than GNU
indent when it comes to more complex code structures, and still closely supports
the current code style. Clang-format unfortunately does not support the
current code style.

-- 
Met vriendelijke groet / with kind regards,
     Guus Sliepen <guus at tinc-vpn.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://www.tinc-vpn.org/pipermail/tinc-devel/attachments/20171003/c2d9d63d/attachment.sig>


More information about the tinc-devel mailing list