views:

208

answers:

2

What are the tools that are most used in the industry for formatting source code, C++ in particular, so to obtain a style consistency of the whole code base? Possibly tools that would allow the user to select which style to apply (e.g. BSD, GNU, etc...)?

I could not find many references on the web to solid, wide-spread tools for such a thing, maybe companies that use these tools build theirs in-house?

A: 

I am yet to see a special tool beyond what your IDE (throw in a small set of standard plug-ins to that) offers you for formatting source code. Of course, there can be organizations that are there that do use them.

You seem to be influenced by the indent tool. Alas, most organizations tend to have their own formatting standards which may/may not relate to one of the styles you mention. They may more suitably be represented by a custom .indent file.

dirkgently
A: 

There doesn't seem to be a single, "standard" code-formatting tool. There's good reason for this: reformatting huge blocks of code is almost always a Bad Idea(1). If nothing else, six months down the line you ARE going to have to merge in changes from another branch, and if you've reformatted your branch, you are doomed. Better to just adapt to the existing code style in existing modules.

1) I would say "always," except for the one exception I've come across: about a thousand lines of comments, containing railroad-track diagrams. They were the ONLY documentation for a critical part the syntax of a published programming language. The previous code owner had edited the using the editor from MASM, which had done very strange things to the whitespace-- lots of intermixed spaces and tabs. The code referred to by the comments did not compile, and I had to know what it was supposed to do... I spent a week reformatting those railroad-track diagrams.

mjfgates