-2

I was working on TICS code quality metrics for the first time, and I have this question.

Many suggest breaking large functions into one or more functions in order to keep complexity less than 15. Doing so would increase number of functions called by the given function, hence average fan out would be increased.

Should we make the decision to decrease fan out or decrease cyclomatic complexity? Decreasing Cyclomatic complexity would increase maintainability, but splitting functions into 2 or more functions would increase the number of function calls, which would cost most memory.

So which of these two metrics is more important to improve?

kc2001
  • 5,008
  • 4
  • 51
  • 92
Apoorva Raju
  • 300
  • 1
  • 14
  • 1
    In my experience, the best metric telling you which changes should be done on some piece of software is the judgement of a skilled software engineer (or better, the judgement of some of them). Formal metrics are too often an attempt to achieve something similar, but cheaper. But, again, you get what you pay for. – Dirk Herrmann Feb 12 '19 at 00:34

2 Answers2

-1

I doubt you'll find a definitive answer. In general, I'd advise worrying more about cyclomatic complexity than fan out. You can reduce the cyclomatic complexity of a method using the extract method refactoring. Assuming that the new method that you extracted has a specific purpose that is easy-to-name, you will have replaced detailed logic (the various conditions) with a summary of those conditions (the extracted method). This should make the code easier to read and maintain.

kc2001
  • 5,008
  • 4
  • 51
  • 92
-1

All software quality metrics (including cyclomatic complexity and fanout) are at best unreliable measures of quality. I would strongly caution against trying to improve any metric just for the sake of it.

Metrics can however be reliably used to draw your attention to code that may need attention. If a class or method scores poorly for some metric, it is worth looking at it and deciding if there really is an issue that should be fixed, but it's developer judgment that should make final call on what action should be taken.

ComDubh
  • 793
  • 4
  • 18