C++ CheckStyle

来源:互联网 发布:链表和动态数组的区别 编辑:程序博客网 时间:2024/05/20 04:26

C++ CheckStyle

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.

  • Java - have the CheckStyle tool.
  • C# - have the StyleCop tool.

Note that I differentiate between a static code analysis tool for checking code layout style (form) and a tool for checking coding style (content) - the latter tool is in fact much more important because it can ensure that programmers adhere to a certain programming standard - typically to ensure that code is not degrading with respect to quality, performance, security and other important factors. But the topic of this post if the code layout style checking tools.

But what about C++?

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.

The hunt for a C++ Code Layout checking/beautifier/pretty-printer tool

But that doesn't mean that there aren't tool around. I've found the following list of tools, which I will update whenever I found new ones. They are listed with no priority or preference in mind.

Table updated June 5th, 2011

NameLatest versionProgrammed inTypeUncrustify  Open sourceAstyle (Artistic Style)2.02 (2011-05-16)C++Open sourceUniversal Indent GUI   Polystyle  CommercialSQCBW   GC! GreatCode   Pork   Vera++1.1.1C++ with Boost library. Rules are written in TclOpen source (Boost Software License)Bcpp (C++ Beautifier) C++ Make pretty Perl and Bash and uses BcppOpen Source (GPL)KWStyle  CommercialJIndent (as of writing this tool is not yet released) (most likely Java)Commercialcppcheck1.48 (2011-04-09)C++ with QtOpen source

But none of them really satisfy my needs for style and indent style and freedom to extension with more layout rules.

What the C++ community needs is an open-source CheckStyle like 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++0X stuff, etc) as this will also be helpful as basis for more advanced static code analysis tools. The major hurdle is that there is not really a good up-to-date C++ grammar freely available.

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).

Programmers can't handle the freedom

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.

Relevant Links

  • A free tool to check C/C++ source code against a set of coding standards?
  • Source code beautifier for c++ (vc++)?
  • Google C++ Style Guide
  • Why Code Readability Matters - March 1, 2011, blogpost Ashod Nakashian.
  • Death to the Space Infidels! - April 13, 2009, Coding Horror blogpost by Jeff Atwood.

原创粉丝点击