Code Improvement Through Cyclomatic Complexity (via DevelopingStorm).
Interesting read. A couple of comments of yours truly:
- I don’t think there’s a need for metrics here. Applying common sense is sufficient. Do you have to scroll to read the whole message?. It’s pretty likely that the method is too complex. More than 2 or three if..then..elses? It’s pretty likely that the method is too complex.
- As the example on page 2 shows, you’ll need to use good judgement when getting rid of cyclomatic complexity. Getting rid of intra-method complexity may introduce complexity on an architectural level. Although I prefer architectural complexity (or, for the lack of a better word – elaborate architecture) over cyclomatic complexity, I don’t think getting rid of two if..then..elses justifies a substantial architectural change. If you re-visit those if..then..elses later on and you feel the need to add a few more if..then..else in the same method, go for the architectural change. But go for it when there’s an actual need and not for the sake of architectural beauty.