Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatic code-style-guide test for C++ [duplicate]

Possible Duplicate:
A free tool to check C/C++ source code against a set of coding standards?

I am starting a c++ project involving several people I have no direct access to. We agreed on a coding style guide, which e.g. defines the casing for class members depending on the accessibility (i.e. privates in pascal case, publics and protecteds in camel case. Please, don't start discussions about the style guide. I had enough. Thank you.).

What I want to do now is to generate some reporting of style guide violations. I don't want to enforce the style guide, e.g. at commit, but I want to provide a tool which each developer can use to see where his/her code violates the style guide (if he/she wants to check it).

Do you know a tool which can do the Job?

(It needs to be able to understand some C++, e.g. to detect the accessibility of class members.)

like image 964
Knowleech Avatar asked May 30 '12 15:05

Knowleech


People also ask

How to check code Style in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. To configure a scheme for new projects, go to File | New Projects Setup | Settings/Preferences for New Projects | Editor | Code Style.

What naming convention does c use?

The first character of the name should be a letter and all characters (except the period) should be lower-case letters and numbers. The base name should be eight or fewer characters and the suffix should be three or fewer characters (four, if you include the period).

What is C programming style?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.

How do you write a good CPP?

Here are some hints for writing better C++ programs, in no particular order: Write only one statement per line. Limit lines to 80 characters maximum. When using line comments (i.e., comments at the end of a line of code), be sure that the comments on different lines begin in the same column.


2 Answers

well, you could run your code through AStyle or Uncrustify on commit, which would at least re-format bad code to some standard. I find that's the majority problem with code commits and standards - if you reformat after commmit, it shows up as a lot of delta changes that are entirely trivial.

Otherwise, check the other SO answer.

like image 102
gbjbaanb Avatar answered Oct 17 '22 04:10

gbjbaanb


Style guides tends to be company-specific, and one has to write company-specific checks to achieve them.

My company offers customizable C++ style checkers, in which one can check for deprecated idioms by syntax, check that variables and types have certain properties, or verify that certain commands occur in certain orders locally. These checkers use C++ dialect precise parsers on the source code. The customization isn't easy; you need the underlying engine and some knowledge of parsing C++ programs.

It is possible to write rules that check for layout, but it is a lot of unrewarding work, and resolving such complaints isn't a productive use of programmer resource IMHO. And if you aren't going to enforce your style, why are you annoying the programmer with complaints at all? IT seems easier (as another poster noted) to simply run a layout-formatter that produces the right result at no cost to the programmer.

One of the issues with generic formatters is that being language-imprecise, they may misinterpret the source code and sometimes break it as they format, leading to compilation errors, debugging and wasted time. We also offer C++ Formatters to accomplish the formatting using the same language precise parsers as the style checker; they can't break your code during reformatting.

like image 1
Ira Baxter Avatar answered Oct 17 '22 05:10

Ira Baxter