Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of static code analysis

What are the benefits of doing static code analysis on your source code? I was playing around with FxCop and I was wondering if there any benefits beyond making sure you are following the coding standards.

like image 894
Satish Avatar asked Sep 19 '08 18:09

Satish


2 Answers

There are all kinds of benefits:

  1. If there are anti-patterns in your code, you can be warned about it.
  2. There are certain metrics (such as McCabe's Cyclomatic Complexity) that tell useful things about source code.
  3. You can also get great stuff like call-graphs, and class diagrams from static analysis. Those are wonderful if you are attacking a new code base.

Take a look at SourceMonitor

like image 61
torial Avatar answered Oct 26 '22 06:10

torial


Many classes of memory leaks and common logic errors can be caught statically as well. You can also look at cyclomatic complexity and such, which may be part of the "coding standards" you mentioned, but may be a separate metric you use to evaluate the algorithmic "cleanliness" of your code.

In any case, only a judicious combination of profiling (dynamic or run-time analysis) and static analysis/linting will ensure a consistent, reliable code base. Oh, that, and a little luck ;-)

like image 31
Matt J Avatar answered Oct 26 '22 05:10

Matt J