Kayıtlar

Cyclomatic Complexity

Resim
To enhance understandability in our code, cyclomatic complexity must be limited. Cyclomatic complexity is related to the structural complexity of the code which being analysed. High complexity leads to a high number of defects and maintenance costs. In order to calculate cyclomatic complexity, we have to create a graph. Also this metric give us results related to testability. The general formula to compute cyclomatic complexity is: M = V(G) = E - N + 2P Graf Terimleri V(G) = Cyclomatic number of G E = Number of edges N = Number of nodes P = Number of unconnected parts of the graph If there are no branches, the cyclomatic complexity level is 1. As branches raise cyclomatic complexity levels rise.          Code Highlighting Example          #include 1. void exampleFunction(int a, int b) { 2. if (a > b) { 3. std::cout << "a is greater than b" << std

Measuring Cognitive Complexity in Software

Resim
When you look at a piece of code, do you ever find yourself rereading the same page, or thinking that it could have been written differently to be easier on the eyes? It's moments like these that bring forth the concept of cognitive complexity. In this article, I'll delve into understanding, measuring, and reducing cognitive complexity in code to enhance readability. Cognitive complexity, which is related how we grasp the functioning of the code in our minds, is one of the measurement criteria used to assess the readability of a piece of code (class, function). This concept also indicates how difficult it would be to test a piece of code. Having a low value for cognitive complexity is desired, as it indicates that the code is highly readable.          Code Highlighting Example          #include <iostream> void myMethod(int value) {   bool isCheck = true;   for (int i = 2; i <= value; ++i) { // +1     for (int j = 2; j < i; ++j)