whenever
we write code, it is advisable to test the complexity of the code we
are writing. This will help in source code maintainability, readability
etc.
The best algorithm to do the same is cyclomatic complexity. (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
One of the utility implementing this algorithm is pmccabe.
This ain't any IDE also! A simple CLI utility.
install:
sudo apt-get install pmccabe
usage:
<username>@<hostname>:~~$ find ./ -name *.c | xargs pmccabe | sort -nr | head -10
49 49 116 361 134 <file>(362):<function>
The first column indicates the complexity score of each of the functions mentioned.
The wiki suggests that the complexity score should be kept below 10, and in inevitable cases, it can go upto 15.
No comments:
Post a Comment