--- img: /img/complexity.jpg title: Complexity author: Jeff Russo pdate: March 28,2020 desc: What is complexity as it relates to software? --- The most [relevant definition of complexity](https://www.lexico.com/en/definition/complex) for this blog post is: (adj) "Not easy to analyze or understand; complicated or intricate." Intuition of complexity is important if you are designing, writing, or reading software. If you are purchasing software, it is important to prioritize simpler options; it will be cheaper in the long run. In this blog post, I will discuss identifying complexity, why it's bad, why simple is good, and how software engineers manage complexity. ## Identifying Complexity Before being able to manage complexity, it must be identified. In addition to the definition, it is helpful to know indicators and examples. Seasoned engineers sometimes call these smells; complexity is not black and white, but more of an intuition. Some things that are simple now will become complex in the future. #### Indicators * Incomprehensible: Something complex is difficult to comprehend or articulate. It may have too many parts, or the interaction between the parts is complicated. * Fragile to change: Complex things are not easily modified. An internal combustion engine is complex. If one was to modify the bore of the cylinders, special machining and new parts are required. * Multi-purpose: A tool that can, "do it all," usually does nothing well due to its complexity. #### Examples * Run on sentences: Sentences that have too many clauses become complex because they are trying to express too many independent, but possibly related, although sometimes unrelated thoughts, and they take more mental energy to comprehend, causing the now frustrated reader to reread it until they can ascertain the author's meaning. * Chess: At a glance, chess is straightforward. There are only six types of pieces, and the board is 8x8. The complexity comes from the [permutation of games](https://www.youtube.com/watch?v=Km024eldY1A). It generally takes [a dedicated decade](https://www.quora.com/How-long-does-it-take-to-become-a-chess-grandmaster) to become a grand master. * Humans: No two humans are the same. DNA on its own is complex; factoring in the expression of DNA is beyond the understanding of any single person. ## Complex Software is Undesirable All software is complex; it is one of the most complex man-made things. Physical creations such as space ships, submarines, and skyscrapers may be complex, but they are limited by the laws of physics. Software has no such limit. [FreeBSD](https://www.freebsd.org/) is an operating system that was first released in 1993. Using [scc](https://github.com/boyter/scc), a tool to estimate the size of codebases, it is shown to take about 16 years with 500 people to recreate FreeBSD 12.1. While some complexity is unavoidable, it is best minimized. Complex software is difficult to reason about and therefore difficult to rule out bugs. This is code that an adversary would enjoy combing through, trying to find an exploit. { reasons it is undesirable } ## Software Engineers Program, but Programmers do not Engineer A programmer understands software languages and can program a computer to accomplish tasks. A software engineer will do the same, with the addition of minimizing the program's complexity. In fact the act of minimizing the complexity may take up almost all the time of a software engineer. Many other tasks such as designing, testing, documenting, refactoring, and code reviews are much more time intensive -- and important -- than the actual programming. Software engineers must create programs that are simple enough to be understood by other engineers. This enables others to work on the project and create something greater than the sum of the engineers' abilities. ## Simple is Difficult, but Effective [An antonym of complexity is simplicity.](https://www.thesaurus.com/browse/complexity) Although it is easy to express what a [simple system](https://simplesystems.tech/blog/post/simplicity) is, it is not easy to create one. Simplicity is so effective in software that many books and blogs are written on the topic. A few examples of simplifying principles: * Encapsulation: This is a very powerful idea, especially when some complexity cannot be mitigated -- it can still be encapsulated. * UNIX philosophy: "Make each program do one thing well." This can save software from becoming an indomitable mess. Constantly adding features to the same system will eventually make it collapse in on itself. * Composition: Software should be composed of interchangeable modules. The boundaries between modules must be well-defined. None of these principles are easy to incorporate into an engineering process. There is both a science and art aspect of designing and building something in a simple manner. Once a system becomes simple, the benefits are exponential. One important benefit for teams to think about is number of engineers who can work on a project. If a system becomes an interconnected mess, usually only 1 or 2 people can work on it simultaneously. If a system is well designed, especially using modularity, the number of engineers who can work on it simultaneously is practically unlimited, because each module is independent. ##### ? Monero provides a simple interface, but it was not easy to create. There is a lot going on behind the scenes. ##### Reference Rob Pike's comments on GC (The simplest interface is none at all) https://www.youtube.com/watch?v=rFejpH_tAHM ##### MVCC ? Maybe a complex topic for a post on reducing complexity ##### ? design patterns