3 ms·
The real answers about complexity come from thinking about why we even care. It's because our feeble minds have to build internal models of the code so we can w
by SKILNER 5y ago
The real answers about complexity come from thinking about why we even care. It's because our feeble minds have to build internal models of the code so we can work with it. The cognitive aspects of building those models is why complexity matters.
What things make it more difficult to build those models? A partial list, mostly as others have mentioned:
- tool and library dependencies
- nested conditions
- loops and especially nested loops
- asynchronous processing, callbacks, etc
- non-descriptively named variables and functions
- using non-standard code patterns for standard functionality
- delocalized code, as in, you have to navigate somewhere else to see it (throws off your working memory)
By one study, developers using Eclipse for Java spent 27% of their time just doing code navigation.
The starting point for code complexity is about how our minds work.
As many people have said, "it's easier to write a program than read it."
- deleted 5y ago[deleted]
- ip26 5y agoI would argue complexity is also the wellspring of corner cases. The more corner cases, the more mercurial- and that isn’t just due to the limitations of our minds.
- kristov 5y agoNot just build internal models of the code, but also an internal model of the execution of the code. For example, a mental model of the scoping rules. As a developer you have to read a function and build a model of when variables are assigned values - you have to execute the code in your head to understand what the state will be at a particular point in time. I think a big part of complexity is having to imagine what the current in-flight state is - the larger the current in-flight state, the harder to reason about how the code will interact with it.