
{"id":186,"date":"2013-02-25T15:14:12","date_gmt":"2013-02-25T14:14:12","guid":{"rendered":"http:\/\/serverdude.dk\/?p=186"},"modified":"2013-02-25T15:15:10","modified_gmt":"2013-02-25T14:15:10","slug":"big-ball-of-mud-with-physics","status":"publish","type":"post","link":"https:\/\/serverdude.dk\/?p=186","title":{"rendered":"Big Ball of Mud with physics"},"content":{"rendered":"<p>\nBeing a fan of <a href=\"https:\/\/twitter.com\/bigballofmud\">Foote<\/a> and Yoder&#8217;s <a href=\"http:\/\/www.laputan.org\/mud\/\">Big Ball of Mud paper<\/a>. Well, fan in the sense that I think it is a correct observation of most software developed, yet not liking that fact.<\/p>\n<p>\nSo I have been pondering on this \u00e2\u20ac\u201c donning my amateur physicists hat I have contemplated some of the issues.<\/p>\n<h2>Tournaround<\/h2>\n<p>\nLet&#8217;s say that we have a  team of developers pushing the project forward. Let&#8217;s call them <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sisyphus\">Sisyphus<\/a>. They have a development velocity, v. The ball of mud has a radius, r, which is comparable to the number of features in the product. The angular veloticy, \u00cf\u2030, is proportional to the frequency of revolution, let&#8217;s denote this as the version number.<\/p>\n<p>\n\u00cf\u2030 = v\/r<\/p>\n<p>\nThat is, as the radius grows, then \u00e2\u20ac\u201c given the velocity is constant \u00e2\u20ac\u201c the angular velocity reduces, which in turn means that the versions will be harder to crank out.<\/p>\n<p><h2>Work<\/h2>\n<p>\nWork, W, is force, F, times the distance, s, which in turn is the velocity times the time passed.<br \/>\nThe force is mass times acceleration, and the mass is density, \u00cf\u0081, times the volume, V.<\/p>\n<p>\nW = F \u00ce\u201ds<br \/>\n\u00ce\u201ds = v t<br \/>\nF = m a = \u00cf\u0081V a<\/p>\n<p>The volume of a sphere is 4\u00cf\u20ac r<sup>3<\/sup>\/3<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-work1.png\" alt=\"ball-work\" title=\"ball-work\" width=\"188\" height=\"25\" class=\"alignnone size-full wp-image-188\" \/><\/p>\n<p>\nThus the work is proportional to the radius of the sphere cubed.<\/p>\n<p><h3>The interpretation<\/h3>\n<p>If something requires twice the number of features, then the work required will be 2<sup>3<\/sup> = 8 times greater or run at 1\/8 the velocity.<\/p>\n<p>\nIf \u00e2\u20ac\u201c on the other hand \u00e2\u20ac\u201c this could be done in two disjoint balls of mud, it would only require twice the amount of work.<\/p>\n<p>\nMore generally, we could probably divide the features of the big ball of mud into two smaller balls having different radii, R and r.<\/p>\n<p>\nThe Volume of the original ball with radius R+r will be:<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-volume1.png\" alt=\"ball-volume\" title=\"ball-volume\" width=\"611\" height=\"24\" class=\"alignnone size-full wp-image-193\" \/><\/p>\n<p>\nWith the volumes of each of the lesser balls as:<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/balls-volume.png\" alt=\"balls-volume\" title=\"balls-volume\" width=\"97\" height=\"47\" class=\"alignnone size-full wp-image-197\" \/><\/p>\n<p>\nEffectively being <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-bigger.png\" alt=\"ball-bigger\" title=\"ball-bigger\" width=\"99\" height=\"18\" class=\"alignnone size-full wp-image-196\" \/> smaller than the larger ball. We are actually saving more than 6 times the volume of the smallest ball.<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-excess.png\" alt=\"ball-excess\" title=\"ball-excess\" width=\"443\" height=\"22\" class=\"alignnone size-full wp-image-195\" srcset=\"https:\/\/serverdude.dk\/wp-content\/uploads\/ball-excess.png 443w, https:\/\/serverdude.dk\/wp-content\/uploads\/ball-excess-300x14.png 300w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/p>\n<p>\nIf we split the big ball into <a href=\"http:\/\/en.wikipedia.org\/wiki\/Pareto_principle\">80% and 20%<\/a> \u00e2\u20ac\u201c which is likely, then the combined volumes of those two smaller balls would save<br \/>\n <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-save.png\" alt=\"ball-save\" title=\"ball-save\" width=\"501\" height=\"23\" class=\"alignnone size-full wp-image-198\" srcset=\"https:\/\/serverdude.dk\/wp-content\/uploads\/ball-save.png 501w, https:\/\/serverdude.dk\/wp-content\/uploads\/ball-save-300x13.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><br \/>\n48% of the original volume.<\/p>\n<p>\nIf volume is comparable to complexity, then we will save complexity and development effort in keeping the balls as small as possible. Nothing new there.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/biball.png\" alt=\"biball\" title=\"biball\" width=\"472\" height=\"312\" class=\"alignnone size-full wp-image-184\" srcset=\"https:\/\/serverdude.dk\/wp-content\/uploads\/biball.png 472w, https:\/\/serverdude.dk\/wp-content\/uploads\/biball-300x198.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/p>\n<p>\nThis is just another argument for low coupling and high cohesion. But it is also a reminder that we must look at our code from a different perspective from time to time. Are classes adhering to the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Single_responsibility_principle\">Single Responsibility Principle<\/a>? <\/p>\n<h2>Disjoint Communication<\/h2>\n<p>\nIf the Big Ball of Mud is split into several smaller balls, they would probably need to communicate. This would have been some of the intrinsic complexity we shaved off. <\/p>\n<p>\nLet us try to add it in the most stupid form possibly: A <a href=\"http:\/\/en.wikipedia.org\/wiki\/Complete_graph\">complete graph<\/a> in which each and every ball will know and communicate with each and every other ball.<\/p>\n<p>Renaming the radii having R as the radius of the original Bug Ball of mud, and divide it into n = R\/r balls of approximately the same diameter, r. Then taking the added complexity into account we get n(n-1)\/2 additional entanglement. Leaving us with:<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-entangled.png\" alt=\"ball-entangled\" title=\"ball-entangled\" width=\"484\" height=\"23\" class=\"alignnone size-full wp-image-202\" srcset=\"https:\/\/serverdude.dk\/wp-content\/uploads\/ball-entangled.png 484w, https:\/\/serverdude.dk\/wp-content\/uploads\/ball-entangled-300x14.png 300w\" sizes=\"auto, (max-width: 484px) 100vw, 484px\" \/><\/p>\n<p>Which about the original volume divided by 2n.<\/p>\n<p>\nAs a complete graph is just inverting the big ball of mud, there is a minimum of n-1 connections for a completely connected graph. That is, the refactored ball of mud could \u00e2\u20ac\u201c at best \u00e2\u20ac\u201c save an additional factor of n.<\/p>\n<p><h3>Different distributions<\/h3>\n<p>What if the balls cannot be split using an equal distribution? Perhaps we should contemplate a more natural distribution such as a power law.<\/p>\n<h4>Doubling down<\/h4>\n<p>Dividing the original radius into n different sizes each half the length of the previous, but with twice as many balls. <\/p>\n<p>\nDividing into n=4 different sizes we get:<\/p>\n<p>1\/4 + 2\/8 + 4\/16 + 8\/32 = 4\/4 = 1<\/p>\n<p>\nThat is, we get 2<sup>4<\/sup>-1 = 15 balls, the biggest of radius R\/4.<\/p>\n<p>\nThe general formula for volume per size is now:<\/p>\n<p>V(c,r) = 4\/3 \u00cf\u20ac c r<sup>3<\/sup><\/p>\n<p>\nWhere c is the number of balls with the radius, r. <\/p>\n<p>As the communication is no longer of equal size, we have to do some more work. The rectangle spanned by the two communicating parties radii seems a fitting proporsition.<\/p>\n<p>We end up with the following formula for added complexity due to full communication needs:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/ball-comm-sum.png\" alt=\"ball-comm-sum\" title=\"ball-comm-sum\" width=\"307\" height=\"23\" class=\"alignnone size-full wp-image-203\" srcset=\"https:\/\/serverdude.dk\/wp-content\/uploads\/ball-comm-sum.png 307w, https:\/\/serverdude.dk\/wp-content\/uploads\/ball-comm-sum-300x22.png 300w\" sizes=\"auto, (max-width: 307px) 100vw, 307px\" \/><\/p>\n<p>As R is a factor of all radii, we see that Vcomm is an area in R2, whereas the volume, V, is a volume in R3. This means that we shouldn&#8217;t be allowed to add them, but as we&#8217;re not concerned with this type of detail we add them anyway but notice that the effect is dependent upon the initial radius, R.<\/p>\n<p>Using the relative complexity as the yardstick, we can plot the effect of R and n. Remembering that we&#8217;re getting 3 balls for n=2, 7 balls for n=3, and 15 balls for n=4.<\/p>\n<p>From the graph it looks as though the initial radius doesn&#8217;t matter as much.<\/p>\n<p>Furthermore, it seems that the best value would be to split into 2 or 3 different sized smaller balls. Going beyond seems futile as the gain from splitting the largest ball left would probably be bigger \u00e2\u20ac\u201c given that the initial radius doesn&#8217;t matter as much.<\/p>\n<p>Without full communication needs the relative complexity would be even lower.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/serverdude.dk\/wp-content\/uploads\/doubledown.png\" alt=\"doubledown\" title=\"doubledown\" width=\"525\" height=\"534\" class=\"alignnone size-full wp-image-185\" srcset=\"https:\/\/serverdude.dk\/wp-content\/uploads\/doubledown.png 525w, https:\/\/serverdude.dk\/wp-content\/uploads\/doubledown-294x300.png 294w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>While it is human nature to hoard development into a single monolithic big ball of mud. It does pay off to break down the monolith to a certain degree. Whether for sanity, savings, or speed.<\/p>\n<p>\nThe notion of equal distribution \u00e2\u20ac\u201c which corresponds to disection into primitive obsession \u00e2\u20ac\u201c is luckily reverted by the doubling down distribution. Which is likely to be a more natural division of elements.<\/p>\n<p>It does seem counterintuitive to work at a constant pace and still grind to a halt. Yet this seems to be a logical conclusion of the above calculations. If not to a complete standstill, then at least turning so slowly that it seems like a complete stop.<\/p>\n<p>I didn&#8217;t consider friction in the above calculations. Friction would impact on the complete forces, and thus on the work \u00e2\u20ac\u201c but not in a positive way.<\/p>\n<p>The question now is: Will a Big Ball of Mud collapse under its own weight if not cared for?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Being a fan of Foote and Yoder&#8217;s Big Ball of Mud paper. Well, fan in the sense that I think it is a correct observation of most software developed, yet not liking that fact. So I have been pondering on this \u00e2\u20ac\u201c donning my amateur physicists hat I have contemplated some of the issues. Tournaround [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":15,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":211,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions\/211"}],"wp:attachment":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}