When your code is marked on an automated system which picks up CC, and you NEED a 16 case switch

It looks like it's half an understanding of logical analysis.

If you run through all the paths of the code, you get every possible abstract permutation of state. This is an NP hard problem to analyze (you have to define the scope of your program - how many instances of 'objects' can exist and what behavior you want to test).

The half they are missing is the part where you can computationally check whether the code contains logical inconsistencies.

When you generate possible abstract state and functionality of code, you can check to see how the objects and functions behave in the code. You are basically running test cases, except software does this (like model checkers) and it can generate (given a defined scope for each instance of each model in the logic) complex behavior of the logic. After generating what is essentially SAT for your logic, the computer can simplify these abstractions by removing 'duplicate' abstractions (things that have the same logical form and structure) Then the human looks at it (the generated instances of code) and says "yes, this is correct behavior of my program" or "no, I did not intend for this to happen"

The advantage of it is that a human is biased when they run unit tests. They know what the code looks like and they have a behavior they learned through experience of how to test. A computer isn't limited to this nature, it is only limited by time and space. Therefore, these tools can help programmers by showing them how their code may execute, given a reduced set of assumptions (where the code executes, who is using it, whether they know how to use it, whether they misuse it, etc.)

The CC metric itself IS stupid and it's programmers that are kicking themselves in the ass for using it to judge code. You can have very complex code that is perfect and runs perfectly and will never throw errors because you account for every possible variation of probabilistically likely unknowns combined with the known rules of your logic. It doesn't ensure perfect code, but it ensures it within some degree of measurable tolerance.

/r/ProgrammerHumor Thread Parent Link - i.imgur.com