A well known tehnique of measuring a routine's complexity is proposed by Tom McGabe, by counting the "decision points". The tehnique is described below:

- Start with 1 for the straight path through the routine.
- Add 1 for each of the following keywords, or their equivalents: if, while, repeat, and, or.

- Add 1 for each case in a case statement

If the score is:

- 0-5: the routine is probably fine
- 6-10: start to think how to simplify the routine
- >10: break the routine into smaller ones

These begin said, I personally think this method is far from perfect. Yet it is easy to understand and apply. Also, the studies show an improve in code quality when using it. Wouldn't it be nice to be intergated in your IDE?

## No comments:

Post a Comment