Shotgun surgery

Shotgun surgery is an antipattern in software development and occurs where a developer adds features to an application codebase which span a multiplicity of implementors or implementations in a single change. This is common practice in many programming scenarios as a great amount of programming effort is usually expended on adding new features to increase the value of programming assets. As a consequence these new features may require adding code in several places simultaneously where the code itself looks very similar, and may only have slight variations. Owing to the fast paced nature of commercial software development there may not be sufficient time to remodel (or refactor) a system to support the new features trivially. As a consequence the practice of cut and paste coding is prevalent; the code is written in a single place then simply copied to all other places where that implementation is required (with any required changes applied in-place). This practice is generally frowned on by the refactoring community as a direct violation of the Once and Only Once principal - ultimately any change to the new functionality may require widespread changes. Further to this any potential software bug in this new feature will be replicated manifold and can make bugfixing particularly difficult and tedious. Even in the absence of copied code the implementations are guaranteed to be very similar and just as prone to requirements change or bugfixing. This form of software development tends to favour short-term improvement (in the form of additional features) at the cost of long-term maintainability and stability.
The canonical example of this practice is logging which generally adds prologue code to many functions simultaneously, per example:
void MyFunc()
{
...
}
void MyFunc2()
{
...
}
...
void MyFuncN()
{
...
}
Could be transformed to:
void MyFunc()
{
printf("Entering MyFunc() ");
...
}
void MyFunc2()
{
printf("Entering MyFunc2() ");
...
}
...
void MyFuncN()
{
printf("Entering MyFuncN() ");
...
}
Here a single requirement has added similar code to several functions simultaneously. As such any change in requirements here (viz. adding line numbers to the log) would now require a considerable effort. It is important to note that shotgun surgery is not synonymous with cut and paste coding, as highlighted by this trivial example. The practice of copying code can be viewed as a "means to an end", where shotgun surgery is merely an "end" (i.e. there are many ways to reach the same conclusion).

Consequences of Shotgun Surgery

The concerns with this style are by-and-large the same as those for any duplication in a software system; that is, duplicating the same logic in many places can vastly increase the costs of making changes to the same logic later. Some of the aforementioned costs are measurable, others are not (at least not trivially).
Typically some combination of the following is to be expected:

  • Increased developer effort and reduced throughput
  • Associated monetary cost of the above (as in commercial development)
  • Psychological effects and potential neglect of code

  • Of these the most insidious is the psychological effect which can exponentially lead to software rot. When uncontrolled this can cause entire codebases to become unmaintainable. Generally the only solution to this problem is to completely rewrite the code (at substantial cost).

    Mitigation

    The most promising approach to solving this problem lies with Aspect oriented programming (AOP). This aims to reduce these forms of invasive modifications in favour of adopting an "aspect" or "concern". The solutions take the form of boilerplate code which can be applied over a domain of functions simultaneously (through the process of weaving) which vastly reduces the amount of duplicated code. The use of Domain Specific Languages is also becoming more widespread where light-weight compilers are written to generate most of the duplicated code on the behalf of the programmer. Both methods fall into the broader categories of code generation and automation.

    Sources

    *http://sourcemaking.com/refactoring/shotgun-surgery
    *http://ieeexplore.ieee.org/Xplore/login.jsp?url=/iel5/10728/33849/01611587.pdf?temp=x


    Wikimedia Foundation. 2010.

    Look at other dictionaries:

    • Goldie Lookin Chain — Live at Leeds Festival 2005 Background information Origin Newport, South Wales …   Wikipedia

    • Smell (Programmierung) — Unter Code Smell, kurz Smell (engl. ‚[schlechter] Geruch‘) oder deutsch übelriechender Code versteht man in der Programmierung ein Konstrukt, das eine Überarbeitung des Programm Quelltextes nahelegt. Dem Vernehmen nach stammt die Metapher… …   Deutsch Wikipedia

    • Full genome sequencing — Genome sequencing redirects here. For the sequencing only of DNA, see DNA sequencing. An image of the 46 chromosomes, making up the diploid genome of human male. (The mitochondrial chromosome is not shown.) Full genome sequencing (FGS), also… …   Wikipedia

    • School shooting — School shooter redirects here. For the Half Life 2 mod, see School Shooter: North American Tour 2012. Terrorism Definitions · Counter terrorism Inter …   Wikipedia

    • Aqua Teen Hunger Force (season 2) — Aqua Teen Hunger Force Season 2 Volume Two DVD cover, which features episodes 1 11 from season two Country of origin …   Wikipedia

    • Trauma (medicine) — For other uses, see Trauma. Trauma Classification and external resources …   Wikipedia

    • List of Heartbeat characters — This is a list of characters from the British period police drama Heartbeat. The 18th and final series ended on 12 September 2010. Within each category, characters are listed in order of first appearance. Only regular and recurring characters are …   Wikipedia

    • List of Sons of Anarchy characters — This is a list of characters from Sons of Anarchy. Sons of Anarchy is a drama on the American TV network FX; it focuses on the lives of an outlaw motorcycle club in Northern California. Contents 1 Sons of Anarchy Motorcycle Club 1.1 Active SAMCRO …   Wikipedia

    • Rod Stewart — Infobox musical artist Name = Rod Stewart Img capt = Rod Stewart in Oslo (1976) Img size = Landscape = Background = solo singer Birth name = Roderick David Stewart Alias = Rod the Bod Rod the Mod Born = birth date and age|df=yes|1945|01|10 Origin …   Wikipedia

    • medicine, history of — Introduction  the development of the prevention and treatment of disease from prehistoric and ancient times to the 20th century. Medicine and surgery before 1800 Primitive (primitive culture) medicine and folklore       Unwritten history is not… …   Universalium


    Share the article and excerpts

    Direct link
    Do a right-click on the link above
    and select “Copy Link”

    We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.