Is There Any Evidence of the Ripple Effect?
Is there such thing as a butterfly effect that slowly destroys code as it changes, similar to chaos theory? You, uh, better, uh, check it out.
Join the DZone community and get the full member experience.Join For Free
this blog has droned on and on about ripple-effect husbandry (or lack thereof) and how it determines the quality of source code structure. the ripple effect — whereby gently polishing code in one place radiates wobbles and cracks and shattering crashes far and wide — was defined in 1974 and has guided structural toil ever since.
but does it really exist?
or rather: where is the evidence that the ripple effect exists? how would you gather such evidence?
imagine you had 100 glass marbles: 40 red and 60 blue. no, not blue, yellow. ;) you throw them on the floor, close your eyes and pick up one at random. what's the probability that the marble you selected is red?
if you answer, "0.4," or "40%," then well done: you grasp probability theory. replace the marble and repeat the experiement 10,000 times: you will find that your selection history closely approximates that initial ratio: perhaps 4095 red to 5905 yellow. love that law of large numbers.
changing the experiment trivially for reasons that will shortly become clear: let's say you now have 10,000 scattered marbles — 4,000 red, 6,000 yellow — and instead of selecting a single marble, you pick up, say, 200 marbles at random and put them in a bag. what proportion of this sample will be red marbles?
yes: approximately 40%. this is really little different from performing the single selection 200 times: if there's a 40% chance of selecting a red marble, then roughly (though seldom exactly) 40% of the marbles in your bag will be red.
now, consider a method invoking another method, that is, depending on another method. let's call all methods that do not depend on any others, "child methods," and all methods that do depend on any other, "parent methods." hence in figure 1, only a() is a child method.
figure 1: main() and wonder() are parent methods, a() is a child.
imagine you have a system of 10,000 methods, 40% of which are parent methods and 60% of which are child methods. chose 200 methods at random. what will be the ratios of parent and child methods in your selection?
yes: approximately 40% of the methods will be parent methods. this is the same experiment as with the bag of marbles above.
total snoozefest so far, right?
now, however, let's examine some real java software systems as they were released over time and let's select a number of methods in each successive release. we won't, however, select randomly. instead, we'll select those methods updated during that release.
programmers update methods for many reasons, but few meetings begin with, "quick! we need to update 300 parent methods, which ones will we chose?" so if we select the updated methods of a release, of course that selection itself is not random in that programmers do not sit around in their underwear flipping coins to chose which methods to update. yet nor do they explicitly select for parentness or childness, so whether a parent or child is selected should be random because mentally balanced programmers don't care. if a release contains 40% parent methods and 60% child methods, then we should expect to see these proportions reflected approximately in the set of methods updated in that release: 40% of the updated methods should be parents, 60% of the updated methods should be child methods. roughly.
the ripple effect, however, predicts something different.
the ripple effect concerns dependencies, those, " ... paths along which changes and errors can propagate into other parts of the system." with the direct dependency from parent to child being the strongest dependency, the ripple effect — if it exists — predicts that there will be a slight bias towards parents in the set of updated methods: more parents will be updated than child methods. this is because whereas both parent and child methods can be updated independently, there is a greater probability that a parent method will be updated because of a child's update rippling to it, than vice versa (as parents depend on child methods, not vice versa).
certainly, if there were no bias towards parents in the updated set, then we may even have evidence that a ripple effect does in fact not exist and forty years of software structuring could be chucked in the river in a black plastic bag.
figure 2 shows 21 successive releases of the apache maven core jar file. the red line shows the percentage of maven's methods that were parent methods in any given release, which is also the percentage of that release's updated methods that are predicted to be parent methods. the blue line shows the percentage of updated methods that were actually parent methods in each release.
if a ripple effect exists, the blue line should be higher than the red.
figure 2: parent updates as a percentage of all updated methods per maven release.
that's not just a little bias. parent methods form a vastly larger proportion of maven's updated methods than we would expect if both parents and child methods shared the same probability of update.
but perhaps maven is somehow an oddity? we need to inspect hundreds of thousands of method revisions in completely independent software projects to draw any conclusions. fortunately ...
figure 3 shows 19 successive releases of fitnesse .
figure 3: parent updates as a percentage of all updated methods per fitnesse release.
figure 4 shows 13 successive releases of junit .
figure 4: parent updates as a percentage of all updated methods per junit release.
figure 5 shows 21 successive releases of the apache log4j core jar file.
figure 5: parent updates as a percentage of all updated methods per log4j release.
figure 6 shows 25 successive releases of the apache lucene core jar file.
figure 6: parent updates as a percentage of all updated methods per lucene release.
figure 7 shows 21 successive releases of the spring core jar file.
figure 7: parent updates as a percentage of all updated methods per spring release.
figure 8 shows 19 successive releases of struts .
figure 8: parent updates as a percentage of all updated methods per struts release.
no one seriously doubts the existence of ripple effects, and all of this is, really, blindingly obvious. the above, futhermore, presents not evidence but correlation (and, what's more, correlation facing a host of validity-threats). as a foundation for all syntactic software structuring everywhere ever, however, even an unrefined correlation sometimes convinces where just saying, "it's blindingly obvious," does not.
to a previous post which attempted to show the structural utility of comparing dependency distributions, the excellent paul hanchett made an insightful comment, pointing out that coupling — methods calling methods — " ... can introduce adverse dependencies between sections of code. it's that dependency that you're trying to avoid, not the coupling."
this post tried to find just that correlation between merely depending on a method and an increased probability of being updated because of that dependency. hence we'll name this, "the hanchett correlation," unless paul objects.
Opinions expressed by DZone contributors are their own.