Code metrics and warnings for C++ [closed]
Asked Answered
S

4

11

I have a pretty new code base written in C++. Already I'm starting to see some bad practices creeping into the project (class file with 1000+ lines of code, functions with a lot of parameters, ...).

I would like to stop on these right away with some automated tools which can hook into the build and check for poor coding practices. What suggestions do you have for such tools? I'm interested in metrics but really more interested in a stylistic sort of lint which would highlight functions with 37 parameters.

Spoliation answered 9/6, 2009 at 22:42 Comment(1)
Duplicate: #93760Cryptography
N
3

As with the others I'm not sure of a tool that will judge style. But CCCC will produce numerous metrics that can help you find the trouble spots. Metrics like cyclomatic complexity will give you quantitative evidence where the problem spots are. The downside is that you will have to incorporate these metrics with a style guide that you adopt or create on your own.

Niacin answered 13/11, 2010 at 16:53 Comment(2)
Note that by now CCCC is way outdated. The latest activity on their website is from 2002 and only support Microsoft Visual Studio 2003 framework. I also had troubles running it, since it was not that much User friendly. I highly recommand SourceMonitor: campwoodsw.com/sourcemonitor.html instead, as Torial suggested.Tutorial
@ForceMagic: I believe CCCC is still a viable choice when not running Windows since SourceMonitor does seem to require Windows. There's also a Jenkins plugin to hook it into a build and to visualize regressions.Kipkipling
D
6

I'm sorry I can't help you with respect to style, but a great metrics tool which supports C++ and is free: SourceMonitor.

In particular, you will get good info like Cyclomatic Complexity (which I find of more value for bad programming practice than number of parameters), as well as lines of code, percentage of comments, longest function, etc.

Give it a try -- and it is very fast as well.

Duvetyn answered 9/6, 2009 at 22:58 Comment(1)
When using this tool, try Modified Complexity. I'm quoting the the SourceMonitor help: The Modified Complexity metric option changes the way the complexity metric is defined for new checkpoints added to a project. When this option is enabled, SourceMonitor computes the complexity metric by adding one to the complexity for each switch statement. The case statements within a switch statement are parsed for other metrics, but the case statements themselves do not contribute to the complexity (as they do when this option is not enabled).Pantelleria
N
3

As with the others I'm not sure of a tool that will judge style. But CCCC will produce numerous metrics that can help you find the trouble spots. Metrics like cyclomatic complexity will give you quantitative evidence where the problem spots are. The downside is that you will have to incorporate these metrics with a style guide that you adopt or create on your own.

Niacin answered 13/11, 2010 at 16:53 Comment(2)
Note that by now CCCC is way outdated. The latest activity on their website is from 2002 and only support Microsoft Visual Studio 2003 framework. I also had troubles running it, since it was not that much User friendly. I highly recommand SourceMonitor: campwoodsw.com/sourcemonitor.html instead, as Torial suggested.Tutorial
@ForceMagic: I believe CCCC is still a viable choice when not running Windows since SourceMonitor does seem to require Windows. There's also a Jenkins plugin to hook it into a build and to visualize regressions.Kipkipling
M
1

Metrix++ matches this use case and has got several metrics you are probably interested in. Check it here: http://metrixplusplus.sourceforge.net/

Metametabel answered 12/8, 2013 at 10:39 Comment(2)
It's usually considered to be good form to make it very explicit when you're recommending your own product.Tomasz
Thanks. Will know about this and do next time. The answer still matches the question.Metametabel
B
-1

Make sure that you always compile with -Wall compiler option and make it practice that no code is to be checked in if warnings persist.

Find a standard style to follow like this one.

Bledsoe answered 9/6, 2009 at 23:11 Comment(2)
-Wall doesn't automagically warn against the issues OP mentioned (long functions, high cyclomatic complexity).Kipkipling
Your this one link is broken which makes the whole sentence useless. Maybe you're referencing the Google C++ Style Guide?Pantelleria

© 2022 - 2024 — McMap. All rights reserved.