<p><a href="https://stackoverflow.com/questions/20702/whats-youra-good-limit-for-cyclomatic-complexity">This question</a> on <a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity" rel="nofollow noreferrer">Cyclomatic Complexity</a> made me think more about <a href="http://en.wikipedia.org/wiki/Static_code_analysis" rel="nofollow noreferrer">static code analysis</a>.  Analyzing code complexity and consistency is occasionally useful, and I'd like to start doing it more.  What tools do you recommend (per language) for such analysis?  <a href="http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis" rel="nofollow noreferrer">Wikipedia</a> has a large list of tools, but which ones have people tried before?</p>

<p><strong>Edit:</strong> As David points out, this is not a completely unasked question when it comes to <a href="https://stackoverflow.com/questions/2873/choosing-a-static-code-analysis-tool">C/UNIX based tools</a>.</p>

[{'answer_id': 20790, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 0, 'selected': False, 'text': "<p>The only time I've ever used one of those tools is Split (C programming language). I thought it was helpful, but I was by no means a power user and I think I barely scratched the surface of what it could do.</p>\n"}, {'answer_id': 20796, 'author': 'TimK', 'author_id': 2348, 'author_profile': 'https://Stackoverflow.com/users/2348', 'pm_score': 2, 'selected': False, 'text': "<p>I use the PMD plugin for Eclipse a lot.  It's pretty nice, and very configurable.  CheckStyle is also good, if you're looking for more of a style enforcer.</p>\n"}, {'answer_id': 20805, 'author': 'BZ.', 'author_id': 2349, 'author_profile': 'https://Stackoverflow.com/users/2349', 'pm_score': 3, 'selected': False, 'text': '<p>For .Net we use NDepend. It is a great tool and can be integrated to the build (we use CCNet).</p>\n\n<p><a href="http://www.ndepend.com/" rel="nofollow noreferrer">http://www.ndepend.com/</a></p>\n\n<p>HTH.</p>\n'}, {'answer_id': 20808, 'author': 'Craig H', 'author_id': 2328, 'author_profile': 'https://Stackoverflow.com/users/2328', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Lint_programming_tool" rel="nofollow noreferrer">Lint</a> is the only one I have used at a previous position.  It wasn\'t bad, most of the things it suggested were good catches, some didn\'t make much sense.  As long you don\'t have a process in place to ensure that there are no lint errors or warnings, then it is useful to perhaps catch some otherwise hidden bugs</p>\n'}, {'answer_id': 20809, 'author': 'Bill the Lizard', 'author_id': 1288, 'author_profile': 'https://Stackoverflow.com/users/1288', 'pm_score': 2, 'selected': False, 'text': "<p>Checkstyle, Findbugs, and PMD all work pretty well in Java.  I'm currently pretty happy with PMD running in NetBeans.  It has a fairly simple GUI for managing what rules you want to run.  It's also very easy to run the checker on one file, an entire package, or an entire project.</p>\n"}, {'answer_id': 20847, 'author': 'Chris Conway', 'author_id': 1412, 'author_profile': 'https://Stackoverflow.com/users/1412', 'pm_score': 2, 'selected': False, 'text': '<p>Obviously, the answer depends on the programming languages. <a href="http://spinroot.com/uno/" rel="nofollow noreferrer">UNO</a> is good for C programs.</p>\n\n<p>@Thomas Owens: I think you meant Splint.</p>\n'}, {'answer_id': 23815, 'author': 'cschol', 'author_id': 2386, 'author_profile': 'https://Stackoverflow.com/users/2386', 'pm_score': 1, 'selected': False, 'text': '<p>We use Programming Research\'s <a href="http://www.programmingresearch.com" rel="nofollow noreferrer">QAC</a> for our C code. Works OK. </p>\n\n<p>Recently we have been talking about checking out some of the more advanced and static/dynamic code analyzers like Coverity\'s <a href="http://www.coverity.com/html/coverity-prevent.html" rel="nofollow noreferrer">Prevent</a> or the analysis tool by <a href="http://www.grammatech.com/" rel="nofollow noreferrer">GrammaTech</a>. </p>\n\n<p>They claim to not only do static analysis but also find runtime errors etc. One major selling point is supposed to be fewer false positives. </p>\n'}, {'answer_id': 23819, 'author': 'Chris Hanson', 'author_id': 714, 'author_profile': 'https://Stackoverflow.com/users/714', 'pm_score': 3, 'selected': False, 'text': '<p>For C and Objective-C, you can also use the <a href="http://llvm.org/" rel="nofollow noreferrer" title="LLVM - Low Level Virtual Machine">LLVM</a>/<a href="http://clang.llvm.org/" rel="nofollow noreferrer" title="LLVM Clang C &amp; Objective-C Compiler">Clang</a> <a href="http://clang-analyzer.llvm.org/" rel="nofollow noreferrer" title="Clang Static Analyzer">Static Analyzer</a>.</p>\n\n<p>It\'s Open Source and under active development.</p>\n'}, {'answer_id': 152181, 'author': 'Ben Combee', 'author_id': 1323, 'author_profile': 'https://Stackoverflow.com/users/1323', 'pm_score': 1, 'selected': False, 'text': '<p>We use <a href="http://www.coverity.com/" rel="nofollow noreferrer">Coverity Prevent</a> at Palm for C and C++ code analysis, and it\'s done a great job of uncovering some hidden bugs in our code.  It also finds a lot of not likely to be hit problems, but it\'s easy to mark those as "will not fix" or "not a problem" in the code database that the tool generates.  It is expensive, but the company occasionally does runs on open source projects and provides reports to the maintainers.  They have <a href="http://www.coverity.com/library/pdf/success_palmone_v6.pdf" rel="nofollow noreferrer">a whitepaper about our use of the product</a> on their site if you want to read more about our experience.</p>\n'}, {'answer_id': 2716495, 'author': 'Séverin', 'author_id': 326308, 'author_profile': 'https://Stackoverflow.com/users/326308', 'pm_score': 2, 'selected': False, 'text': '<p>For C++, I use CppCheck. It seems to work fine.</p>\n'}, {'answer_id': 2716812, 'author': 'The GG', 'author_id': 280578, 'author_profile': 'https://Stackoverflow.com/users/280578', 'pm_score': 1, 'selected': False, 'text': '<p>My admins are really cheap, so can I only use really cheap tools:</p>\n\n<p>1) CCCC (C / C++ Code Counter): Various results related to number of lines (vs. lines of comments, cyclomatic complexity, Information flow, ...)\n2) Semian: Fastest code duplication finder I ever tried.\n3) LOC Metrix: Not very usefull but can help to make a point.</p>\n'}, {'answer_id': 5907795, 'author': 'Andrew Thompson', 'author_id': 625595, 'author_profile': 'https://Stackoverflow.com/users/625595', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve used quite a few open-source and commercial static analysis tools across many languages and I find that the overall discussion fits under the umbrella of a concept known as technical debt (<a href="http://andrewmatthewthompson.blogspot.com/2011/05/technical-debt.html" rel="nofollow">which this article goes into detail about</a>).</p>\n\n<p>However for a quick answer, here are my favorites per language:</p>\n\n<ul>\n<li>Java: <a href="http://code.google.com/javadevtools/codepro/doc/index.html" rel="nofollow">Google CodePro Analytix</a> &amp; <a href="http://checkstyle.sourceforge.net/" rel="nofollow">Checkstyle</a></li>\n<li>.NET: <a href="http://msdn.microsoft.com/en-us/library/bb429476%28v=vs.80%29.aspx" rel="nofollow">FxCop</a> &amp; <a href="http://archive.msdn.microsoft.com/sourceanalysis" rel="nofollow">StyleCop</a></li>\n<li>C/C++: <a href="http://www.mccabe.com/why_mccabeIQ.htm" rel="nofollow">McCabe IQ</a></li>\n</ul>\n'}, {'answer_id': 5998075, 'author': 'Steve HHH', 'author_id': 705157, 'author_profile': 'https://Stackoverflow.com/users/705157', 'pm_score': 5, 'selected': False, 'text': '<p>I have been setting up a Hudson continuous integration (CI) build system for my Objective-C iPhone projects (iOS apps), and have compiled a varied list of tools that can be used to analyze my projects during a build:</p>\n\n<ul>\n<li><p><strong>Clang static analyzer</strong>: free, up-to-date stand-alone tool that catches more issues than the version of Clang included with Xcode 4. Active project. -- visit <a href="http://clang-analyzer.llvm.org" rel="nofollow noreferrer">http://clang-analyzer.llvm.org</a></p></li>\n<li><p><strong>Doxygen</strong>: free documentation generation tool that also generates class dependency diagrams. Active project -- visit <a href="http://www.doxygen.nl" rel="nofollow noreferrer">http://www.doxygen.nl</a></p></li>\n<li><p><strong>HFCCA</strong> (header-free cyclomatic complexity analyzer): free Python script to calculate code complexity, but without header files and pre-processors. Supports output in XML format for Hudson/Jenkins builds. Active project. -- visit <a href="http://code.google.com/p/headerfile-free-cyclomatic-complexity-analyzer" rel="nofollow noreferrer">http://code.google.com/p/headerfile-free-cyclomatic-complexity-analyzer</a></p></li>\n<li><p><strong>CLOC</strong> (count lines of code): free tool to count files, lines of code, comments, and blank lines. Supports diffing, so you can see the differences between builds. Active project. -- visit <a href="http://cloc.sourceforge.net" rel="nofollow noreferrer">http://cloc.sourceforge.net</a></p></li>\n<li><p><strong>SLOCcount</strong> (source lines of code count): a free tool to count lines of code and estimate the costs and time associated with a project. Does not appear to be active. -- visit <a href="http://sourceforge.net/projects/sloccount" rel="nofollow noreferrer">http://sourceforge.net/projects/sloccount</a> and <a href="http://www.dwheeler.com/sloccount" rel="nofollow noreferrer">http://www.dwheeler.com/sloccount</a></p></li>\n<li><p><strong>AnalysisTool</strong>: free code analysis tool that measures code complexity and also generates dependency diagrams. Not active. Does not seem to work with Xcode 4, but I would love to get it working. -- visit <a href="http://www.karppinen.fi/analysistool" rel="nofollow noreferrer">http://www.karppinen.fi/analysistool</a></p></li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/20788', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2134/']