1

I'm writing a paper on introductory programming for young learners. To determine the difficulty level of a program, I'd like to draw on the concept of cyclomatic complexity, which I've come across during my research. I'd really appreciate if you could check my figures, as I'm not at all sure about whether I'm doing the maths correctly.

Here is my Scratch program, and the control flow graphs that I derived from it.

The program consists of small concurrent units of code and events. According to the cyclomatic complexity formula M = E − N + 2P, I came up with a complexity of 22.

  • Total number of Edges: 50
  • Total number of Nodes: 56
  • Number of connected components: 14

Do you agree with my solution?

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
pretzel
  • 31
  • 1
  • Welcome to SO. "[ask]", "[Stack Overflow question checklist](https://meta.stackoverflow.com/questions/260648)" and "[Writing The Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)" will help immensely. – the Tin Man Jun 01 '20 at 23:54

1 Answers1

0

I've digged a bit deeper into the issue of cyclomatic complexity and feel that I'm now able to answer the question myself.

First of all, the formula provided in the initial post entails that simple statements can be omitted, as they each are comprise of one edge and one node ultimately nullifying each other. Secondly, my research has revealed that event-listeners do not count for the calcuation of CC, although they contain some sort of logic, for sure. Finally, taking all this into consideration, I come up with the following flow chart:

Flowchart of my program

In the flowchart, it can be seen that there are 11 nodes, 17 edges and 1 component. Therefore, according to the formula (17-11+2), the CC of this particular program is 8.

I'm not a 100-%-sure how concurrent threads are treated when calculating the CC, but as they appear to the Scratch-coder as one whole, I consider them as one connected function. Still, I'd appreciate it if you could confirm my reasoning.

pretzel
  • 31
  • 1