In physics class you learn about the laws of conservation of energy and matter, where matter and energy cannot be created nor destroyed.
I feel like it's the same way with code complexity. To a certain degree, if code is downright spaghetti code then it can be simplified, but after a certain point, getting rid of spaghetti code in one place often results in spaghetti code elsewhere.
Law of conservation of complexity
Moderator: Moderators
Forum rules
- For making cartridges of your Super NES games, see Reproduction.
Re: Law of conservation of complexity
I don't agree. In high-level languages, you can avoid spaghetti code by breaking the logic into smaller functions that do less work. When coding in assembly for slow CPUs, having a lot of nested function calls can really slow things down, but you can use macros instead and achieve the save kind of organization without the performance penalty.psycopathicteen wrote: ↑Sun May 16, 2021 9:56 amgetting rid of spaghetti code in one place often results in spaghetti code elsewhere.
Re: Law of conservation of complexity
Such laws should apply to APIs so conservation should resolve complexity issues.
Re: Law of conservation of complexity
I think a better analogy would be the Second Law of Thermodynamics - code complexity can't be lower than the minimum required to do the job, but it can certainly be higher.
Yeah, that's called ravioli code. It's basically spaghetti code but the spaghetti is virtual - instead of branches and jumps, you're dealing with subroutines, and now you have to hunt through dozens of files in multiple cryptically-named directories to find out where the action happens. It does tend to be more robust, if you're careful with conceptual encapsulation...tokumaru wrote: ↑Sun May 16, 2021 10:18 amI don't agree. In high-level languages, you can avoid spaghetti code by breaking the logic into smaller functions that do less work.psycopathicteen wrote: ↑Sun May 16, 2021 9:56 amgetting rid of spaghetti code in one place often results in spaghetti code elsewhere.
Re: Law of conservation of complexity
Yeah, if you're literally just cutting pieces of code from one place and spreading them around it's not much of an improvement, but if you can break complex tasks into self-contained small tasks, the result is much cleaner and pleasant to work with.
When coding in 6502 ASM, if I find myself using the "branch over a JMP so I can put conditional code hundreds of lines away" technique, that's usually a sign that those big blocks of code should be broken up into smaller parts.
When coding in 6502 ASM, if I find myself using the "branch over a JMP so I can put conditional code hundreds of lines away" technique, that's usually a sign that those big blocks of code should be broken up into smaller parts.
Re: Law of conservation of complexity
I've always thought that the idea of orthonormalization can be applied to languages/programs as well. You want the minimal set of constructs that still covers the entire range of concepts and ideas that you want to model.
Once you have that, everything else builds up in a pretty straightforward manner.
Once you have that, everything else builds up in a pretty straightforward manner.