Code reuse

Code reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software,[1] following the reusability principles.

Overview

Ad hoc code reuse has been practiced from the earliest days of programming. Programmers have always reused sections of code, templates, functions, and procedures. Software reuse as a recognized area of study in software engineering, however, dates only from 1968 when Douglas McIlroy of Bell Laboratories proposed basing the software industry on reusable components.

Code reuse aims to save time and resources and reduce redundancy by taking advantage of assets that have already been created in some form within the software product development process.[2] The key idea in reuse is that parts of a computer program written at one time can be or should be used in the construction of other programs written at a later time.

Code reuse may imply the creation of a separately maintained version of the reusable assets. While code is the most common resource selected for reuse, other assets generated during the development cycle may offer opportunities for reuse: software components, test suites, designs, documentation, and so on.[3]

The software library is a good example of code reuse. Programmers may decide to create internal abstractions so that certain parts of their program can be reused, or may create custom libraries for their own use. Some characteristics that make software more easily reusable are modularity, loose coupling, high cohesion, information hiding and separation of concerns.

For newly written code to use a piece of existing code, some kind of interface, or means of communication, must be defined. These commonly include a "call" or use of a subroutine, object, class, or prototype. In organizations, such practices are formalized and standardized by domain engineering aka software product line engineering.

The general practice of using a prior version of an extant program as a starting point for the next version, is also a form of code reuse.

Some so-called code "reuse" involves simply copying some or all of the code from an existing program into a new one. While organizations can realize time to market benefits for a new product with this approach, they can subsequently be saddled with many of the same code duplication problems caused by cut and paste programming.

Many researchers have worked to make reuse faster, easier, more systematic, and an integral part of the normal process of programming. These are some of the main goals behind the invention of object-oriented programming, which became one of the most common forms of formalized reuse. A somewhat later invention is generic programming.

Another, newer means is to use software "generators", programs which can create new programs of a certain type, based on a set of parameters that users choose. Fields of study about such systems are generative programming and metaprogramming.

Types of reuse

Concerning motivation and driving factors, reuse can be:

Reuse can be categorized further:

Concerning form or structure of reuse, code can be:[5]

Fork-reuse is often discouraged because it's a form of code duplication, which requires that every bug is corrected in each copy, and enhancements made to reused code need to be manually merged in every copy or they become out-of-date. However, fork-reuse can have benefits such as isolation, flexibility to change the reused code, easier packaging, deployment and version management.[5]

Systematic software reuse

Systematic software reuse is a strategy for increasing productivity and improving quality of the software industry. Although it is simple in concept, successful software reuse implementation is difficult in practice. A reason put forward for this is the dependence of software reuse on the context in which it is implemented. Some problematic issues that needs to be addressed related to systematic software reuse are:[6]

Examples

Software libraries

A very common example of code reuse is the technique of using a software library. Many common operations, such as converting information among different well-known formats, accessing external storage, interfacing with external programs, or manipulating information (numbers, words, names, locations, dates, etc.) in common ways, are needed by many different programs. Authors of new programs can use the code in a software library to perform these tasks, instead of "re-inventing the wheel", by writing fully new code directly in a program to perform an operation. Library implementations often have the benefit of being well-tested, and covering unusual or arcane cases. Disadvantages include the inability to tweak details which may affect performance or the desired output, and the time and cost of acquiring, learning, and configuring the library.[7]

Design patterns

A design pattern is a general solution to a recurring problem. Design patterns are more conceptual than tangible and can be modified to fit the exact need. However, abstract classes and interfaces can be reused to implement certain patterns.

Frameworks

Main article: Software framework

Developers generally reuse large pieces of software via third-party applications and frameworks. Though frameworks are usually domain-specific and applicable only to families of applications.

Higher-order function

Main article: Higher-order function

In functional programming higher-order functions can be used in many cases where design patterns or frameworks were formerly used.

Retrocomputing

Retrocomputing encompasses reuse of code, simply because retro programs are being run on older computers, or emulators for them.

For instance, some code from MS-DOS has been reused so as to make the DOSBox DOS emulator.

Computer security

In computer security code-reuse is employed as a software exploit method.[8] When an attacker is not able to directly input code to modify the control flow of a program, for example in presence of code injection defenses such as W⊕X, he can redirect the control flow to code sequences existing in memory.

Examples of code-reuse attacks are return-to-libc attack, return-oriented programming, and jump-oriented programming.[8][9]

Components

Main article: Software component

A component, in an object-oriented extent, represents a set of collaborative classes (or only one class) and its interfaces. The interfaces are responsible for enabling the replacement of components.

Outside of computers

The whole concept of "code reuse" can also encompass engineering applications outside of software. For instance, parametric modeling in computer-aided design allows for creating reusable designs. Standardization results in creation of interoperable parts that can be then reused in many contexts.

Criticism

Code reuse results in dependency on the component being reused. Rob Pike opined that "A little copying is better than a little dependency". When he joined Google, the company was putting heavy emphasis on code reuse. He believes that Google's codebase still suffers from results of that former policy in terms of compilation speed and maintainability.[10]

See also

References

  1. Frakes, W.B. and Kyo Kang, (2005), "Software Reuse Research: Status and Future", IEEE Transactions on Software Engineering, 31(7), July, pp. 529–536.
  2. Lombard Hill Group. "What Is Software Reuse?". lombardhill.com. Lombard Hill Group. Retrieved 22 October 2014.
  3. Lombard Hill Group. "What Is Software Reuse?". Retrieved 22 October 2014.
  4. McConnell, Steve; Rapid Development: Taming Wild Software Schedules, (1996), ISBN 978-1-55615-900-8
  5. 1 2 Colombo, F. (2011), "It's not just reuse" – http://sharednow.blogspot.com/2011/05/its-not-just-reuse.html
  6. Champman, M; Van der Merwe, Alta (2008), Contemplating Systematic Software Reuse in a Small Project-centric Company, Saicsit 2008, South Africa.
  7. "Code reuse". DocForge. Retrieved 15 December 2009.
  8. 1 2 Bletsch, Tyler (2011). "Code-reuse Attacks: New Frontiers and Defenses". North Carolina State University.
  9. Bletsch, Tyler; Jiang, Xuxian; Freeh, Vince W; Liang, Zhenkai (2011). "Jump-oriented programming: a new class of code-reuse attack". Proceedings of the 6th ACM Symposium on Information, Computer and Communications Security. ACM. pp. 30–40.
  10. The Go Programming Language (2015-12-01), Go Proverbs – Rob Pike – Gopherfest – November 18, 2015, retrieved 26 February 2016

External links

This article is issued from Wikipedia - version of the 10/14/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.