Several Concepts and types of duplicate code (clone code)

Source: Internet
Author: User

The content of this article comes from the following two references:

[1] chanchal K. roy, James R. cordy, Rainer koschke. comparison and Evaluation of code clone detection techniques and tools: a qualitative approach. science of computer programming, 2009, 74 (7): 470-495.

[2] Hamid Abdul Basit, Stan jarzabek. A data mining approach for detecting higher-level clones in software. IEEE Transactions on software engineering, 2009, 35 (4): 497-513.

 

Code fragment:A code fragment (CF) is any sequence of code lines (with or without comments .) it can be of any granularity, e.g ., function Definition, begin-end block, or sequence of statements. a CF is identified by its file name and begin-end line numbers in the original code base and is denoted as a triple (cf. filename, cf. beginline, cf. endline ).

Code snippet:A code snippet (CF) is a sequence of any code lines (may contain comments or comments ). It can be of any granularity. For example, a code snippet can be a function definition, a begin-end statement block, or a statement sequence. A code snippet can be identified by its file name, starting line number in the source code, and ending line number. It can be represented by a triple: Cf. filename (file name), cf. beginline (starting line number of the code line), cf. endline (end code line number ).

 

Code clone:A code fragment CF2 is a clone of another code fragment CF1 if they are similar by some given definition of similarity, that is, F (CF1) = f (CF2) where F is the similarity function. two fragments that are similar to each other form a clone pair (CF1, CF2), and when combine fragments are similar, they form a clone class or clone group.

Code clone:Code snippet CF2 is a clone of another code snippet CF1, which defines that they are similar according to some given similarity, that is, F (CF1) = f (CF2 ), F indicates the similarity function. Two similar code snippets constitute a clone pair (CF1, CF2). Multiple similar code snippets constitute a clone class) or clone group ).

 

Clone type:There are two main kinds of similarity between code fragments. fragments can be similar based on the similarity of their program text, or they can be similar based on their functionality (independent of their text ). the first kind of clone is often the result of copying a code fragment and pasting into another location. in the following we provide the types of clones based on both the textual (Types 1 to 3) and functional similarities:

Type-1:Identical code fragments before t for variations in whitespace, layout and comments.

Type-2:Syntactically identical fragments must t for variations in identifiers, literals, types, whitespace, layout and comments.

Type-3:Copied fragments with further modifications such as changed, added or removed statements, in addition to variations in identifiers, literals, types, whitespace, layout and comments.

Type-4:Two or more code fragments that perform the same computation but are implemented by different syntactic variants.

Clone type:There are two main types of similarity between code snippets. The similarity between the first type of snippets is based on the similarity between their program texts, the second type of similarity is functional-based (independent from program text ). The former is usually generated by copying a code snippet and pasting it to another location. Next we provide four types of clone types based on text (type 1 to type 3) and function similarity:

Type 1:Except for spaces, la S, and comments, the rest are the same code snippets.

Type 2:Code snippets with the same syntax structure except identifier, literal volume, type, space, layout, and comment.

Type 3:In addition to the identifier, literal volume, type, space, layout, and comment, the cloned code segment is further modified, such as modifying, adding, or deleting statements.

Type 4:Two or more code snippets perform the same calculation, but the syntax structure is implemented in different ways.

 

The above four types of clones are collectively referred toSimple clone)To combine simple clones into high-level coarse-grained ClonesStructural clone).

 

【Author】 Liu WeiHttp://blog.csdn.net/lovelion]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.