Why Cycles Explode Complexity
By -?Chris Chedgey
Originally posted on the?Structure101 Blog.
Software developers and architects
rather than something like this (same components but with cyclic dependencies)…
Why? Well the second system has about 2x the number of dependencies. But it seems more than twice as complex. I could create an acyclic model with the same number of dependencies as the second, and we would probably be happy enough with it. There’s something about the cycles themselves.
One thing is for sure – cycles make it much harder to tell the story of a codebase. For the first system I can quite easily explain how PNUnit uses NUnit, which does this, and uses Codeblast for that, and Colors for something else, and so forth. I can’t describe the second system in the same way. I can try to explain that PNUnit uses NUnit, which uses CP, which uses TestLibraries, which uses NUnit (again) and PNUnit (which as already mentioned uses NUnit) and Log4net which uses Testlibraries which uses Log4net (again) which…
zzzz…!
Explainability
This can be measured.
Cumulative Component Dependency (CCD)
In Large-Scale C++ Software Design, John Lakos talks about dependency (and thereby complexity) being cumulative. His Cumulative Component Dependency, or CCD, recognizes that when one item depends on a second, it really depends on all the items that the second item depends upon, and that they depend upon, repeat. For instance an item can be impacted when anything in its dependency closure changes. The CCD of a system is the sum of the dependencies of every item in the system. It is a very good indicator of the relative complexity of systems. Here’s how it works.
领英推荐
In this simple example with N = 7 items (from John’s book), the items on the bottom row are considered to be dependent only on themselves; the items on the second row are each dependent on themselves plus 2 items on the bottom row; the top item is dependent on itself plus the 2 sets of 3; CCD is the sum of all the numbers, so for this system it is 17.
The overall number of items and dependencies impacts the CCD somewhat, but when dependencies form cycles, the effect on CCD is explosive.
For example the dependencies for this set of items all point downward (and are therefore acyclic), and its CCD is something less than 164 (it would be 164 if every item depended on every item on the next row down, which isn’t the case). By adding a single dependency from the item on the bottom layer to the item at the top, we create cycles.
The impact on the system coupling
In this example we know which is the disruptive dependency because we added it to the clean, acyclic structure and then highlighted it on the resulting diagram. But in reality cyclic dependencies can make a system an order of magnitude harder to understand and maintain, whatever way you measure it.
#structure101 #softwarearchitecture #codequality #complexity #cyclicdepenencies
Chris Chedgey?is a co-founder of?Structure101, and has 30 years experience in commercial software development, notably on large military and aerospace projects in Canada, including 5 years on the International Space Station (ISS).?
He is a strong advocate for the importance of good software structure, and has spoken at many user groups and conferences including JFall, WICSA, Oredev, JavaOne, Houston Techfest, JAX, Javaland, 33rd Degree, JFocus, JAX Finance and Devoxx.