If you are responsible for reviewing, maintaining, or testing pascal based
source code the application of cyclomatic complexity can be used to assist you
in determining areas of your source code that require the most attention. It
provides you with a highly systematic and standardized measurement that can
quickly focus you on the areas of your source code that can benefit from
increased effort in refactoring and unit testing. This is provided with bias
on source formatting preferences or other readability factors that can often
tend towards personal preferences amongst individual developers.
I am sure we have all looked at a routine, a module, or a class and had to
read through it more than twice to get some idea of what was going on. When this
happens you immediately become more tentative about applying changes to that
particular bit of code. In practice, this is often an indicator that the code
should actually be modified to enhance your ability to maintain
that segment of code. If you don't have any unit test cases you are much more
likely to leave it along or worse yet, dive right in. By measuring the cyclomatic
complexity of the routine before you start it will quickly give you an idea of
the number of test cases that should exist to exercise the routine and whether
the routine has reach a level of complexity that it should be seriously examined
for reconstructive surgery (ala rewrite).
I spend more time reviewing and/or editing code that is not my own; and over time
have been able to develop a decent sense of how complex a module is after a
visual scan or two. The only problem with this is that no matter how hard you try
you end up applying your personal formatting preferences as a penalty to the
underlying code. This isn't fair and it certainly isn't following a great process.
Using cyclomatic complexity has helped me be much more fair and better focus
review efforts.
The other significant benefit of applying cyclomatic complexity measurements to
your source code is that it provides a clear and statistical message
that you can take to your management responsible for resourcing. With this
information in hand you will have a much stronger case for allocation of resources
to make internal software changes that cannot be directly related to software
features or client requested change requests. Using these figures together with
your developer's maintenance investment hours can be a geat way to focus your
group on code improvements that pay in the long run.
The RTS Cyclomatic Complexity calculator is provided both in binary and source
forms. If you are comfortable with compiling and installing source packages I recommend
you start with the source package (besides, then you can tweak it). If you want
to get started quickly and easily than just download the package that matches
the version of Delphi you have, install it, and you are off to the races.
You can provide feedback, bugs, and suggestions by sending an e-mail to
ryan @ run-time-systems.com. Please be sure to include CCP as part of the
subject line otherwise it may not get noticed or claimed as spam.