What is Cyclomatic Complexity?

后端 未结 15 1326

A term that I see every now and then is \"Cyclomatic Complexity\". Here on SO I saw some Questions about \"how to calculate the CC of Language X\" or \"How do I do Y with th

15条回答
  •  不思量自难忘°
    2020-12-07 20:30

    Consider the control flow graph of your function, with an additional edge running from the exit to the entrance. The cyclomatic complexity is the maximum number of cuts we can make without separating the graph into two pieces.

    For example:

    function F:
        if condition1:
           ...
        else:
           ...
        if condition2:
           ...
        else:
           ...
    

    Control Flow Graph

    Control Flow Graph

    You can probably intuitively see why the linked graph has a cyclomatic complexity of 3.

提交回复
热议问题