Updated 2013.05.03 23:48 +0200 |
Every programmer is developing in group of programmers. The smallest group is yourself and yourself a couple of weeks later. If you can't communicate easily to yourself how can you expect to communicate to others?
Any decent professional programmer understand that when developing in groups a good best practice is to use a common code layout style of the source code - mostly to make communication easier. It is much more easy to understand something when the form - the layout - is the same every time, instead of being different, confusing, misleading and right-out annoying due to different layout styles of source code files received from different programmers.
So many modern programming languages have a (static code analysis) tool for checking that a source code file is in compliance with a specific code layout style.
I've been programming for many years in C++ and frankly speaking I've seen every conceivable type of style of code layout that you can imagine. What I've learn is that communication between programmers is more noise free if the source code files shared between programmers are kept in a fixed standard code layout style. New developers get much more quickly into the jargon and can focus on the real job - to fix a bug or implement a new feature, and the more experienced programmers can more easily spot novice mistakes etc.
But C++ do not have a standard tool for checking code layout style. There are many different compilers and many different editors - developed by different vendors, but none of them provides tools for checking C++ code layout style.
But that doesn't mean that there aren't tools around. I've found the following list of tools, which I will update from time to time. They are listed with no order of priority or preference in mind.
Table updated May 3rd, 2013
|Name||Latest version||Programmed in||License||Comments|
|Clang-format||3.3||C++, Python||Open source||Promising tool under development that uses clang's abstract syntax tree. Presently formatting is fixed to 3 different standard formats. It does not
provide options to customize format.
See slides and video from LLVM meeting april 2013.
|Astyle (Artistic Style)||2.03 (April 2013)||C++||Open source||Supports C/C++, C# and Java. Good support for different options, but do not offer full freedom for customized format. Is maintained by only a few developers and have few maintenance releases (approx. one release every year).|
|JIndent||(most likely Java)||Commercial||Supports C/C++ and Java/SQLJ. Seems to support very customizeable formatting, see e.g. documentation.|
|Vera++||1.1.1||C++ with Boost library. Rules are written in Tcl||Open source (Boost Software License)|
|Bcpp (C++ Beautifier)||C++|
|Make pretty||Perl and Bash and uses Bcpp||Open Source (GPL)|
|Universal Indent GUI||1.2.0 (January 2012)||Not itself a code layout tool, but a utility that presents a GUI for activating a code layout (beautifier/indenter/tidy) tools for different programming languages. Some of these listed in of this table.|
|cppcheck||1.59 (March 2013)||C++ with Qt||Open source||Is not really a code layout tool, but a static analysis tool.|
The most difficult part is to implement a parser that sufficiently parses C++ source code well enough for checking code layout style. I would prefer a parser that covers C++ 100% (including preprocessor, templates, C++11 stuff and comments) as this will also be helpful as basis for more advanced static code analysis tools.
Preferably the tool should both be able to check a source code file for compliance and - if desired - automatically change the source code file to be compliant. The tool should be available on the command line and is most likely a good candidate for a plug-in in many editors and build environments (running before or after a compiler).
It seems to me that we programmers cannot handle the freedom of the free layout style of our favorite programming language. So programming language creators better learn from past mistakes; that the layout style of the language is also important - and they better stick to a fixed layout style. It will help everybody.