Cyclomatic Complexity Metric
James Derrick, Pascal Programmer
v1.0.a0 © 1997 James Derrick
If you have problems or suggestions, email me at firstname.lastname@example.org. If possible, please use the bug reporting application that I have provided with the plugin.
The Metrics package contains the following:
Download the Metrics package
This is a plug in for the Codewarrior IDE to calculate the cyclomatic complexity metric for Pascal source code. I am putting this up for comment on its usefulness. I am particularly interested in any problems that you might encounter with it. I am also interested in suggestions for other coding errors that you think that you think that this code analyser should pick up.
The cyclomatic complexity metric is a measure complexity of a routine, originally described by Tom McCabe. More information is available in a large number of references, including "Code Complete".
The score is basically the number of decision points in a routine + 1. Decision points are taken to be
and each limb of a case statement.
If the routine has a score of 5 or less, it is fairly simple.
If the score is 6-10, it has been suggested that you start to think about ways of simplifying it.
Greater than 10 you should simplify the routine.
The way that I have implemented it
Scores of 8-10 will give you a note.
Scores of 11-19 will give you a warning
Scores of 20 or greater will give you an error.
I have implemented this as a compiler plugin for the Codewarrior IDE.
To use it:
1. Put the file "Metrics" into the compiler plugins folder.
2. Put the folder "Metrics PPC" into the Pascal folder inside the (Project Stationery) folder.
3. Create a new project using the Metrics stationery.
4. Add any files that you wish to analyse to the project.
5. Run, compile or make the project.
Note, the code analyser will only analyse TEXT files with filenames ending in .p or .pas.
Although I have implemented this as a compiler extension, no object code is generated, and the files are never updated. No attempt is made to change the source code in any way. The original files are opened with read only permission, and closed as soon as the file has been read. The plug in will not check the correctness of your code, only its complexity.
Although I don't try to change the source in any way, it would be sensible to have a backup before you run this analyser over it.
Only works on a PPC. Requires Codewarrior 9 or greater. (I should mention that I have only tested it on Codewarrior 11).
I am uploading this plugin FREE, as a service to the Pascal community, and in the hope that you will help me find any errors in my code. It is worth what you paid for it! I make no guarantee explicitly or implicitly that the plugin will work, that it is bug free, that it won't destroy your valuable source code, reformat your hard disc, telephone ex partners or notify Microsoft about pirated software on your hard disk. If you choose to use this plugin it is entirely at your own risk. Changing your source code to decrease complexity may introduce new bugs. I retain all rights to the ownership of the plugin. The source code is a trade secret belonging to me, James Derrick. Any attempt to disassemble or reverse engineer the plugin is expressly prohibited.
1. McCabe, Tom. 1976. "A Complexity Measure." IEEE Transactions on Software Engineering, SE-2, no. 4 (December): 308-20.
2. McConnell, Steve. 1993. "Code Complete". Redmond: Microsoft Press.