Software Cognitive Complexity Measure Based on Scope of Variables
In this paper, we define a Mathematical model of program structure. Mathematical model of program structure defined here provides unified mathematical treatment of program structure, which reveals that a program is a large and finite set of embedded binary relations between current statement and previous ones. Then, a program is considered as a composed listing and a logical combination of multiple statements according to the certain composing rules. We also define the Scope Information Complexity Number (SICN) and present the cognitive complexity based on functional decomposition of software, including theoretical validation through nine Weyuker’s properties.
💡 Research Summary
The paper introduces a novel mathematical framework for modeling program structure and proposes a cognitive complexity metric that explicitly accounts for variable scopes. The authors begin by redefining a program as a finite set of embedded binary relations linking each current statement to its preceding statements. This perspective diverges from traditional control‑flow or data‑flow graphs, treating the source code as a “composed listing” where statements are logically combined according to well‑defined composition rules.
Building on this model, the authors define the Scope Information Complexity Number (SICN). SICN quantifies the informational burden associated with a variable by considering three factors: (1) the lexical scope level at which the variable is declared, (2) the number of assignments or operations performed on the variable within that scope, and (3) the presence of control constructs (if, while, for) that surround those operations. Each scope transition (e.g., from global to function‑local, or from function‑local to block‑local) adds a base increment to the SICN, while each operation contributes a weighted increment reflecting its perceived cognitive difficulty. Consequently, SICN captures both the data‑flow aspect (how often a variable is manipulated) and the structural aspect (how deeply nested its scope is).
Using SICN as a building block, the paper proposes the Functional Decomposition Cognitive Complexity (FDCC). A program is first decomposed into functional units (functions, methods, or modules). For each unit, the sum of SICN values of all variables is computed, and additional weights are applied for inter‑unit calls, call depth, and recursion. The overall FDCC of the program is the aggregate of unit complexities plus the extra cost induced by the call graph. This approach aligns with the intuition that developers perceive complexity not only from individual statements but also from the way functions interact and from the nesting of variable scopes.
To validate the metric, the authors systematically verify that FDCC satisfies all nine of Weyuker’s properties for a robust software complexity measure. The proofs emphasize how the scope‑aware SICN ensures property 5 (different structures for the same functionality yield different complexities) and property 8 (the complexity of a combined program can exceed the sum of its parts). The paper also includes a limited empirical study: classic algorithms (bubble sort, Fibonacci) and selected modules from an open‑source project are evaluated using FDCC, traditional Cognitive Complexity, Cyclomatic Complexity, and Halstead metrics. Correlation analysis shows that FDCC scores align more closely with expert‑rated perceived difficulty, especially in cases where variable scope changes are frequent.
Despite its contributions, the work has notable limitations. Computing SICN requires precise static analysis of scope hierarchies, which can be computationally expensive for large codebases and may struggle with dynamic language features (e.g., eval, reflection). The current formulation focuses on procedural languages; extensions to object‑oriented constructs such as inheritance, polymorphism, and encapsulation are not fully addressed. Moreover, the empirical validation is modest in size and diversity, leaving open questions about the metric’s scalability and generalizability across different programming paradigms.
In summary, the paper offers a fresh mathematical lens for viewing program structure and introduces a scope‑centric cognitive complexity measure that bridges data‑flow and control‑flow considerations. By satisfying Weyuker’s axioms and demonstrating preliminary alignment with human judgments of difficulty, the proposed FDCC advances the state of software complexity metrics. Future work should concentrate on tool support for automated SICN extraction, broaden empirical studies to include large, heterogeneous codebases, and refine the model to accommodate modern language features.