HOME

TheInfoList



OR:

Code reuse is the practice of using existing
source code In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer. Since a computer, at base, only ...
to develop
software Software consists of computer programs that instruct the Execution (computing), execution of a computer. Software also includes design documents and specifications. The history of software is closely tied to the development of digital comput ...
instead of writing new code. ''Software reuse'' is a broader term that implies using any existing software asset to develop software instead of developing it again. An asset that is relatively easy to reuse and offers significant value is considered to have high
reusability In computer programming, reusability describes the quality of a software asset that affects its ability to be used in a software system for which it was ''not'' specifically designed. An asset that is easy to reuse and provides utility is conside ...
. Code reuse may be achieved different ways depending on a complexity of a
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
chosen and range from a lower-level approaches like code copy-pasting (e.g. via snippets), simple functions ( procedures or
subroutine In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times. Callable units provide a ...
s) or a bunch of objects or functions organized into modules (e.g.
libraries A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
) or custom
namespace In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
s, and packages, frameworks or
software suite A software suite (also known as an application suite) is a collection of computer programs (application software, or programming software) of related functionality, sharing a similar user interface and the ability to easily exchange data with eac ...
s in higher-levels. Code reuse implies dependencies which can make code maintainability harder. At least one study found that code reuse at the class level reduces technical debt.


Overview

Ad hoc ''Ad hoc'' is a List of Latin phrases, Latin phrase meaning literally for this. In English language, English, it typically signifies a solution designed for a specific purpose, problem, or task rather than a Generalization, generalized solution ...
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. The key idea in reuse is that parts of a
computer program A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
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. 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 Modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a system into varying ...
, loose coupling, high cohesion, information hiding and
separation of concerns In computer science, separation of concerns (sometimes abbreviated as SoC) is a design principle for separating a computer program into distinct sections. Each section addresses a separate '' concern'', a set of information that affects the code o ...
. 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 In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times. Callable units provide a ...
, object,
class Class, Classes, or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used d ...
, or
prototype A prototype is an early sample, model, or release of a product built to test a concept or process. It is a term used in a variety of contexts, including semantics, design, electronics, and Software prototyping, software programming. A prototype ...
. In organizations, such practices are formalized and standardized by domain engineering, also known as 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 Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impl ...
, 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 Generative may refer to: * Generative art, art that has been created using an autonomous system that is frequently, but not necessarily, implemented using a computer * Generative design, form finding process that can mimic nature’s evolutionary ...
and
metaprogramming Metaprogramming is a computer programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyse, or transform other programs, and even modi ...
.


Types of reuse

Concerning motivation and driving factors, reuse can be: * Opportunistic – While getting ready to begin a project, the team realizes that there are existing components that they can reuse. * Planned – A team strategically designs components so that they'll be reusable in future projects. Reuse can be categorized further: * Internal reuse – A team reuses its own components. This may be a business decision, since the team may want to control a component critical to the project. * External reuse – A team may choose to license a third-party component. Licensing a third-party component typically costs the team 1 to 20 percent of what it would cost to develop internally. The team must also consider the time it takes to find, learn and integrate the component. Concerning form or structure of reuse, code can be: * Referenced – The client code contains a reference to reused code, and thus they have distinct life cycles and can have distinct versions. * Forked – The client code contains a local or private copy of the reused code, and thus they share a single life cycle and a single version. 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.


Systematic

Systematic software reuse is a strategy for increasing productivity and improving the 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 need to be addressed related to systematic software reuse are: *a clear and well-defined product vision is an essential foundation to a software product line (SPL). *an evolutionary implementation strategy would be a more pragmatic strategy for the company. *there exist a need for continuous management support and leadership to ensure success. *an appropriate organisational structure is needed to support SPL engineering. *the change of mindset from a project-centric company to a product-oriented company is essential.


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.


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

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

In
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
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
emulator In computing, an emulator is Computer hardware, hardware or software that enables one computer system (called the ''host'') to behave like another computer system (called the ''guest''). An emulator typically enables the host system to run sof ...
s for them.


Computer security

In
computer security Computer security (also cybersecurity, digital security, or information technology (IT) security) is a subdiscipline within the field of information security. It consists of the protection of computer software, systems and computer network, n ...
code-reuse is employed as a software exploit method. 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 or she 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.


Components

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. Reusable components can also be isolated and synchronized between SCM repositories using component source code management technologies
CSCM
.


Outside computers

The whole concept of "code reuse" can also encompass engineering applications outside software. For instance, parametric modeling in
computer-aided design Computer-aided design (CAD) is the use of computers (or ) to aid in the creation, modification, analysis, or optimization of a design. This software is used to increase the productivity of the designer, improve the quality of design, improve c ...
allows for creating reusable designs.
Standardization Standardization (American English) or standardisation (British English) is the process of implementing and developing technical standards based on the consensus of different parties that include firms, users, interest groups, standards organiza ...
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 Robert Pike (born 1956) is a Canadian programmer and author. He is best known for his work on the Go programming language while working at Google and the Plan 9 operating system while working at Bell Labs, where he was a member of the Unix t ...
opined that "A little copying is better than a little dependency". When he joined
Google Google LLC (, ) is an American multinational corporation and technology company focusing on online advertising, search engine technology, cloud computing, computer software, quantum computing, e-commerce, consumer electronics, and artificial ...
, the company was putting heavy emphasis on code reuse. He believes that Google's
codebase In software development, a codebase (or code base) is a collection of source code used to build a particular software system, application, or software component. Typically, a codebase includes only human-written source code system files; thu ...
still suffers from results of that former policy in terms of compilation speed and maintainability. Reusable code requires usually more effort to write and design.
Fred Brooks Frederick Phillips Brooks Jr. (April 19, 1931 – November 17, 2022) was an American computer architect, software engineer, and computer scientist, best known for managing development of IBM's System/360 family of mainframe computers and the ...
discusses the significantly higher cost associated with that effort in his essays "The Tar Pit" and " No Silver Bullet" The fallacy is that effort is often spent without careful understanding of the mechanisms through which that cost will be redeemed. The justification often comes from incorrectly drawing parallels to reusable parts in a physical manufacturing process. Incorrect because writing code is analogous to design of a single product rather than production of multiple units.


See also

*
Don't repeat yourself "Don't repeat yourself" (DRY) is a principle of software development aimed at reducing repetition of information which is likely to change, replacing it with abstractions that are less likely to change, or using data normalization which avoids r ...
* International Conference on Software Reuse *
Inheritance (object-oriented programming) In object-oriented programming, inheritance is the mechanism of basing an Object (computer science), object or Class (computer programming), class upon another object (Prototype-based programming, prototype-based inheritance) or class (Class-base ...
* Language binding * Not invented here ( antonym) * Type polymorphism *
Procedural programming Procedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as Function (computer programming), procedures (a.k.a. functions, subroutines) that call each o ...
* Reinventing the wheel ( antonym) *
Reuse metrics In software engineering, many reuse metrics and models are metrics used to measure code reuse and reusability. A metric is a quantitative indicator of an attribute of a thing. A model specifies relationships among metrics. Reuse models and metri ...
* Single source of truth *
Software framework In computer programming, a software framework is a software abstraction that provides generic functionality which developers can extend with custom code to create applications. It establishes a standard foundation for building and deploying soft ...
* Virtual inheritance


References


External links


ReNews – an information site about software reuse and domain engineering

Software Reuse Tips Article
{{DEFAULTSORT:Code Reuse Programming principles Repurposing Computer libraries