202410221413
Status: #idea
Tags: #complexity #software_engineering #design_patterns #object_oriented_programming
# Complexity in software development and design
> [!tldr]
> Complexity is anything in a software system that makes the system harder to understand or modify. Complexity is caused by dependencies, which create sections of code that cannot be modified or understood without considering other sections of code, and obscurity, which is when code is difficult to understand due to poor documentation, formatting, and design. Symptoms of complexity include difficult-to-understand code, feature modifications that require modifying code in many different parts of the codebase, and bugs caused by unknown dependencies in the codebase.
Complexity in software can be defined as anything that makes a software system more difficult to understand or modify.
We can represent it mathematically as $C = \sum_p c_p t_p$, where $p$ is the part of the program, $c_p$ is the complexity of that part, and $t_p$ is the fraction of time that developers spend in that part of the program. The implication is that we can reduce overall complexity $C$ by reducing the complexity of the parts *or* by pushing complexity into the parts where developers spend the least amount of time.
Some symptoms of unnecessarily high complexity in software are:
1. **Change amplification** - when one feature needs to be changed, the developer needs to implement the same change in many places in the codebase. For example, if each page in a website explicitly defines its background color and the developer wants to change the background, he must make that same change on every single page
2. **High cognitive load** - the functionality for a single feature in high-complexity code is frequently strewn throughout the code base and entangled with many functions or classes. This makes understanding a feature (a prerequisite for modifying it) unnecessarily difficult for developers
3. **Unknown unknowns** - in many cases in high complexity code, we have dependencies in the code base that are not immediately obvious and cause no breaking changes at compile time. Hence, when a developer modifies a feature that is entangled in these unknown unknowns, he will introduce bugs into the system that will not be identified until a user stumbles across them.
Complexity is caused by two main features in code:
1. **Dependencies** - when a piece of code cannot be understood or modified without considering or modifying another piece of code
2. **Obscurity** - when critical aspects of the code’s functionality are unclear or poorly documented, such as when generic variable names are used or units are not specified.
Dependencies cause change amplification and cognitive load. Obscurity causes cognitive load and unknown unknowns.
---
# References
[[A philosophy of software design]]