\chapter{Related Work}
\label{related}

Mainstream research on clones has primarily focused on clone detection. Surveys
of clone-related research and clone-detection techniques can be found
in~\cite{cloneSurvey-rainer} and~\cite{cloneSurvey-roy}.

As explained in~\cite{inconsistent}, inconsistent changes between clones are
frequent and can be a major source of defects. This implies that cloning can
create substantial development and maintenance problems unless existing clones
and their evolution are carefully tracked. In short, changes to clones are
frequent, and inconsistent clone changes can introduce defects.

In the study described in~\cite{cnp}, we proposed the main design elements for
proactive clone management, aimed at providing better support for clone
evolution. We also described our initial experience prototyping several features
that partially implemented this design, including the consistent renaming utility
CReN and CSeR. Our design for proactive CnP support was partially inspired by
related work, but it differs from that work in important ways. Clone case studies
were used to motivate individual features and to identify or refine design
requirements. Future lab-based user studies can help evaluate these features and
their effectiveness in helping programmers work with clones.

CnP differs by tracking copied-and-pasted clones directly rather than relying on
clone-detection tools. As a result, CnP can support clones that clone-detection
tools may fail to capture. Moreover, clone-detection tools tend to have low
precision and recall~\cite{bellonComparison}, which can create expensive
batch-processing work for programmers. Proactive support can potentially ease
this problem by distributing the effort over time.

Clonescape~\cite{waterlooCnP} and CPC~\cite{weckerleCnP} are recent projects
aimed at developing proactive clone support. CnP differs from Clonescape and CPC
by providing features such as accidental capture of external identifiers,
consistent renaming (CReN), and a clone-difference view (CSeR).

CloneTracker~\cite{cloneTracker} proposes a novel representation for clone
locations that is independent of physical properties such as character offsets or
line ranges. It also supports a form of simultaneous editing by using
Levenshtein distances to locate similar lines between clones. However,
CloneTracker relies on clone detection. CnP may also perform more accurately in
cases where Levenshtein distance is insufficient.

Context Sensitive Cut Copy and Paste (CSCC\&P)~\cite{ccp} is a tool implemented
on the LAPIS\footnote{http://groups.csail.mit.edu/uid/lAPIs/index.html} pattern
matcher platform. The tool detects violations of several common contextual
relationships, including semantic relationships. It is activated by copy or cut
actions, but it differs from CSeR in its operation and goals.

Codelink~\cite{codeLink} supports both clone-difference views and simultaneous
editing. It uses colors to show commonalities between linked clones in blue and
differences in yellow, and uses elision to hide identical parts of the clones
from view. However, unlike CSeR, Codelink does not distinguish between ``new''
and ``updated'' code.

Codelink uses the longest-common subsequence (LCS) algorithm, like the algorithm
implemented by the Unix ``diff'' utility, to determine commonalities and
differences within a clone group. Toomim et al. report two main shortcomings of
the LCS algorithm: potentially long running time and unintuitive results. CnP's
approach to differencing clones can potentially address these problems.

CReN and Rename Refactoring differ mainly in their scope. CReN works in any
user-specified region, while Rename Refactoring works only in predefined scopes
such as blocks and classes.

The Breakaway and Jigsaw tools automatically determine detailed structural
correspondences between two classes and two methods, respectively~\cite{breakaway,jigsaw}.
The inputs to Breakaway and Jigsaw are classes or methods that may contain
different code. The input to CSeR, by contrast, is always initially identical.
CSeR \emph{incrementally} tracks changes as they are made to related clones.
