The Structure of Struts.
Join the DZone community and get the full member experience.Join For Free
the search for structural excellence among the the most popular, open-source, java programs continues with an analysis of apache struts , the much-loved web framework that, " ... works well with conventional rest applications and with nouveau technologies like soap and ajax."
as usual, we shall look at each release's package-structure as a spoiklin diagram in which a circle will represent a package, straight lines will represent dependencies from packages drawn above to those below and curved lines will represent dependencies from packages drawn below to those above. the colour of a package will indicate the relative number package-dependency tuples in which it partakes: the more red, the more dependency tuples.
the visual trawl.
figure 1: struts version 1.0.2.
figure 1 shows the package-structure of struts version 1.0.2 and with it our series of structure analyses gives birth to its first truism: programs begin well-structured .
this is not a vacuous statement. circumstances need not have been so. what factors, then, bring it about?
successful programs accrue features - and hence grow in size - as they
age so young programs are small. small stature, however, does not
necessarily imply well-structuredness: we can make a mess of anything.
the above figure might have presented those floating packages -
etc. - mangled horribly, inextricably together. but it did not. the
figure (ignoring a bow or two) presents a constellation of packages
whose relationships with one another could hardly be clearer.
perhaps, then, the very presence of legacy code - however well-structured - places unbearable constraints on battle-fatigued programmers, forcing them to abandon their principles.
but we are getting ahead of ourselves.
figure 2: struts version 1.1.
version 1.1 adds 700 functions and the number of packages rises from 11
to 26. a programmer might consider the resulting diagram neither pretty
nor ugly. certainly the, "upper half," seems satisfactory with most of
these packages enjoying straight-forward relationships with their
, a self-proclaimed utilities package, must
ever accept its role as dependency-sink and so a certain dependency
clutter may be excused in its vicinity; the same is true of the sinky
appears to provide sufficient difficulty in tracing ripple-effect changes to reduce the overall harmony of this graphic.
nevertheless, the structure seems, overall, ok.
one great praise we might heap on struts concerns its handling of circular function-dependencies: from this version onwards the number of these circular dependencies never spikes above 28, which is remarkably good in a system of (a fairly consistent) 7000 dependency tuples.
figure 3: struts version 1.2.4.
version 1.2.4. loses a package but otherwise structural tensions appear similar to the previous version.
figure 4: struts version 1.3.5.
high above package-level, sweeping changes in version 1.3.5. see its
jar-structure torn apart. whereas previous versions had bulged within
file, figure 4 shows the contents of the
alone. some might raise concerns about comparing like-with-like,
concerns countered by the claim that this analysis focuses not on struts
in its entirety but on its core components alone.
that being said, the new core-components jar holds 1000 fewer functions
and 10 fewer packages than version 1.2.4. as is evidenced by the
pleasing simplification of its diagram. a new
package has unfortunately thrown itself into the fisticuffs of center-stage but overall structural qualities seem undiminished.
figure 5: struts version 2.0.5.
struts2 - versions of struts higher than 2.0 - presents yet another interpretation challenge: for is struts2 structurally a derivation of the first major revision of struts or an entirely independent product? unfortunately, we might have to conclude that the latter holds than the former but the analysis shall continue, presuming (perhaps foolishly) some continuity.
this new version, then, brings with it an extra 1000 functions and does
so gracelessly. tracing ripple-effects through those central
packages looks deeply problematic, the
package alone generating almost 20% of the system's
all is not well.
figure 6: struts version 2.0.11.
figure 6 emphasizes the problem with the
package, namely the orgy of mutual bloody stabbings in which its engages with
. the system has fallen to its lowest lawless level, structurally-speaking.
figure 7: struts version 2.1.6.
figure 7 offers something of a surprise: a noted structural improvement in a mature product.
make no mistake: version 2.1.6. remains a rather tricky system in which to trace dependencies but it at least improves on its predecessor. this appears, however, largely due to version 2.1.6.'s having ejected 700 functions and 8 packages, a material loss caused presumably by sub-surface jar-file tectonics.
in other words, the improvement on display is probably thanks to packages' having been shipped out of our analysis scope. we chalk this one up to good jar-file husbandry.
figure 8: struts version 2.3.8.
little significant happens between version 2.1.6. and the final version in figure 8 (the software accommodates two further packages and accommodates them well). the system comes to rest at a rather intermediate structural state: superior to version 2.0.11. yet inferior to version 1.0.2.
trends and followers.
as usual, no diagram presented here offers conclusive proof of structural value or cost; a high-level analysis can only ever prompt questions whose answers can be found solely through deeper inspection.
yet however we appraise the final configuration of struts in figure 8, one point remains: the structure begs many questions. mutual dependencies abound: how many might prove unjustifiable even after further investigation? and if unjustifiable, how many could have been prevented in the first place?
to put this even more broadly: why was this system - and all systems analyzed so far in this series - allowed to descend to states of such questionable structural sub-optimality?
one answer may lie in the software industry's view of structure itself.
the history of software development resembles that of art in that grand trends tend to buck and veer directed not by institutions or overarching organizations but by individuals. the many follow the few, the opinions of these few holding tremendous sway.
when presented with this series' structural analysis of his excellent junit program, the matchless kent beck wrote , "i appreciate aesthetics in code, but somehow package dependencies have never triggered my ocd. in any case, junit 5 is an api release. repackaging should be decoupled into either 4.12 or 5.1."
the most important point of this quote is that the good mister beck had already planned a re-structuring ("repackaging"): the unswerving dedication to cost-effective improvement marks all great programmers.
slightly troubling, however, is that word, "aesthetics," a word which carries with it an air of the frivolous, of the non-essential adornment. new programmers barging enthusiastically into our field might hear established titans make such utterances and conclude that structure is nothing more than aesthetics and so unworthy of intellectual or commercial pursuit.
this is unfortunate.
yes, the execution of a program governs its user-experience but it is structure that governs its cost of change. it is structure that helps or hinders expensive weekend-consuming bug-hunts. it is structure that underwrites or undermines that desperately-needed feature upgrade. structure is time. structure is commercial survivability.
furthermore, quotes from code-authors inform less than the code itself. a programmer's code definitively broadcasts cherished values. open-source code, for better or worse, offers a model for novitiates to copy, a goal to aspire to. when popular, open-source projects display poor structure they carry no implicit apology, we hear no, "this is below-par but we'll get around to fixing it sometime." on the contrary, that the code is released for public scrutiny shouts clearly, "this is how code should be written! this is how you, too, should structure your code!"
though it strikes as unfair, open-source projects must be held to even higher structural standards than closed-source projects precisely because in making themselves generally available they implicitly claim to embody industry-held principles.
the structure of the struts core components takes top position on the structure leader-board above junit but still falls short of recommendation.
few would argue that testing has triggered something of a revolution in software development during the previous decade or so. software has always been tested, but never in its history has software development sung the praise of testing quite as much as it sings now.
a structure revolution, however, seems far, far away.
Published at DZone with permission of Edmund Kirwan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.