Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing of coding and naming conventions of C/C++ code

I'm looking for a script/tool that can be customized to check and enforce coding/naming conventions on a C/C++ code.

It should check for example:

  • Code lines are wrapped at some length.
  • Private variables have prefix _
  • Code is indented properly.
  • All functions are documented.

Many of the projects I'm working on are outsourced by customers which tend to have various internal coding and naming conventions.

like image 959
zoli2k Avatar asked Apr 04 '10 12:04

zoli2k


People also ask

What are naming conventions in C?

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 are the C coding standards?

A C coding standard is a set of rules for source code that is adopted by a team of programmers working together on a project, such as the design of an embedded system. Programming teams and companies write down their C coding standards for a variety of reasons but often bicker internally about which rules to follow.

What are some conventions for naming identifiers?

The first character of the identifier must be a letter of the alphabet (upper or lowercase) or an underscore ('_'). The rest of the identifier name can consist of letters (upper or lowercase), underscores ('_') or digits (0-9). Identifier names are case-sensitive. For example, myname and myName are not the same.

What is meant by naming convention?

A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.


1 Answers

Don't know if it's really worth the time, but if you really want, you could try building something similar to google's cpplint, which does checking of their style guide.

I personally think that thorough reviews and people's commitment to follow certain conventions is a much better way to make sure your code is "indented properly" and variables named consistently. Maybe invest in making a document like google has done, describing the details of acceptable style, and have people in your company accept it and stick to it.

Why humans are better than a script? The answer is quite simple: people will have to deal with the code later, they should care about the stuff they are writing. A variable name like i will be fine for a script, but not going to slip from my eyes, if it is a clientCount, it should just be named appropriately, script which would be able to do that might take over the world rather soon. :)

like image 135
Dmitry Avatar answered Sep 22 '22 15:09

Dmitry