New! Sign up for our free email newsletter.
Science News
from research organizations

Automatic code reuse: System automatically modifies code for transfer to other programs

Date:
September 20, 2017
Source:
Massachusetts Institute of Technology
Summary:
Researchers have developed a new system that allows programmers to transplant code from one program into another. The programmer can select the code from one program and an insertion point in a second program, and the system will automatically make modifications necessary -- such as changing variable names -- to integrate the code into its new context.
Share:
FULL STORY

Researchers at MIT's Computer Science and Artificial Intelligence Laboratory (CSAIL) have developed a new system that allows programmers to transplant code from one program into another. The programmer can select the code from one program and an insertion point in a second program, and the system will automatically make modifications necessary -- such as changing variable names -- to integrate the code into its new context.

Crucially, the system is able to translate between "data representations" used by the donor and recipient programs. An image-processing program, for instance, needs to be able to handle files in a range of formats, such as jpeg, tiff, or png. But internally, it will represent all such images using a single standardized scheme. Different programs, however, may use different internal schemes. The CSAIL researchers' system automatically maps the donor program's scheme onto that of the recipient, to import code seamlessly.

The researchers presented the new system, dubbed CodeCarbonCopy, at the Association for Computing Machinery's Symposium on the Foundations of Software Engineering.

"CodeCarbonCopy enables one of the holy grails of software engineering: automatic code reuse," says Stelios Sidiroglou-Douskos, a research scientist at CSAIL and first author on the paper. "It's another step toward automating the human away from the development cycle. Our view is that perhaps we have written most of the software that we'll ever need -- we now just need to reuse it."

The researchers conducted eight experiments in which they used CodeCarbonCopy to transplant code between six popular open-source image-processing programs. Seven of the eight transplants were successful, with the recipient program properly executing the new functionality.

Joining Sidiroglou-Douskos on the paper are Martin Rinard, a professor of electrical engineering and computer science; Fan Long, an MIT graduate student in electrical engineering and computer science; and Eric Lahtinen and Anthony Eden, who were contract programmers at MIT when the work was done.

Mutatis mutandis

With CodeCarbonCopy, the first step in transplanting code from one program to another is to feed both of them the same input file. The system then compares how the two programs process the file.

If, for instance, the donor program performs a series of operations on a particular piece of data and loads the result into a variable named "mem_clip->width," and the recipient performs the same operations on the same piece of data and loads the result into a variable named "picture.width," the system will infer that the variables are playing the same roles in their respective programs.

Once it has identified correspondences between variables, CodeCarbonCopy presents them to the user. It also presents all the variables in the donor for which it could not find matches in the recipient, together with those variables' initial definitions. Frequently, those variables are playing some role in the donor that's irrelevant to the recipient. The user can flag those variables as unnecessary, and CodeCarbonCopy will automatically excise any operations that make use of them from the transplanted code.

New order

To map the data representations from one program onto those of the other, CodeCarbonCopy looks at the precise values that both programs store in memory. Every pixel in a digital image, for instance, is governed by three color values: red, green, and blue. Some programs, however, store those triplets of values in the order red, green, blue, and others store them in the order blue, green, red.

If CodeCarbonCopy finds a systematic relationship between the values stored by one program and those stored by the other, it generates a set of operations for translating between representations.

CodeCarbonCopy works well with file formats, such as images, whose data is rigidly organized, and with programs, such as image processors, that store data representations in arrays, which are essentially rows of identically sized memory units. In ongoing work, the researchers are looking to generalize their approach to file formats that permit more flexible data organization and programs that use data structures other than arrays, such as trees or linked lists.


Story Source:

Materials provided by Massachusetts Institute of Technology. Original written by Larry Hardesty. Note: Content may be edited for style and length.


Journal Reference:

  1. Stelios Sidiroglou-Douskos, Eric Lahtinen, Anthony Eden, Fan Long, Martin Rinard. CodeCarbonCopy. Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering, 2017 DOI: 10.1145/3106237.3106269

Cite This Page:

Massachusetts Institute of Technology. "Automatic code reuse: System automatically modifies code for transfer to other programs." ScienceDaily. ScienceDaily, 20 September 2017. <www.sciencedaily.com/releases/2017/09/170920144651.htm>.
Massachusetts Institute of Technology. (2017, September 20). Automatic code reuse: System automatically modifies code for transfer to other programs. ScienceDaily. Retrieved March 28, 2024 from www.sciencedaily.com/releases/2017/09/170920144651.htm
Massachusetts Institute of Technology. "Automatic code reuse: System automatically modifies code for transfer to other programs." ScienceDaily. www.sciencedaily.com/releases/2017/09/170920144651.htm (accessed March 28, 2024).

Explore More

from ScienceDaily

RELATED STORIES