Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the token count in functions/methods used for?

I've been using some tools to measure code quality and CCN (Cyclomatic Complexity Number) and some of those tools provides a count for tokens in functions what does that count says about my function or method? What is it used for?

like image 271
Black Sheep Avatar asked Oct 19 '22 19:10

Black Sheep


1 Answers

Cyclomatic Complexity Number is a metric to indicate complexity of function, procedure or program. The best (large enough and intuitive) explanation I have found is provided here.

I think that tokens refer to conditional statements tokens that actually are taken into account to compute the cyclomatic complexity.

[later edit]

A high CCN means complex code that:

  • it is (much) more hard to read and understand
  • it is hard to maintain
  • unit tests are harder to maintain since a decent code coverage is reached with more difficulty
  • might lead to more bugs

CCN can be reduced using various techniques. Some examples can be seen here or here.

like image 104
Alexei - check Codidact Avatar answered Nov 24 '22 00:11

Alexei - check Codidact