Code reuse
In software development (and computer programming in general), code reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software,[1][2]: 7 following the reusability principles.
Code reuse may be achieved by different ways depending on a complexity of a
Code reuse implies dependencies which can make code maintainability harder.[citation needed] At least one study found that code reuse reduces technical debt.[5]
Overview
This section needs additional citations for verification. (April 2015) |
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.[6] 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.[7]
The
.For newly written code to use a piece of existing code, some kind of
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
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 "
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.[8] 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:[9]
- 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.[9]
Systematic
This section needs expansion. You can help by adding to it. (April 2015) |
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:[10]
- 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
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[citation needed].
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.
Computer security
In computer security code-reuse is employed as a software exploit method.[12] 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.[12][13]
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).[citation needed]
Outside computers
The whole concept of "code reuse" can also encompass engineering applications outside 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.[citation needed]
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.[14]
Reusable code requires usually more effort to write and design. Fred Brooks 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
- International Conference on Software Reuse
- Inheritance (object-oriented programming)
- Language binding
- antonym)
- Type polymorphism
- Procedural programming
- antonym)
- Reusability
- Reuse metrics
- Single source of truth
- Software framework
- Virtual inheritance
References
- S2CID 14561810.
- ^ OCLC 704559821.
- ^ Selaolo, Karabo; Hlomani, Hlomani (2016). "Towards An Algorithms Ontology Cluster: for Modular Code Reuse and Polyglot Programming". Advances in Computer Science. 5: 63 – via Researchgate.
- ^ "4. Code Reuse: Functions and Modules - Head First Python, 2nd Edition [Book]". www.oreilly.com. Retrieved 2022-01-26.
- S2CID 219502749.
- ^ Lombard Hill Group. "What Is Software Reuse?". lombardhill.com. Lombard Hill Group. Archived from the original on 23 January 2019. Retrieved 22 October 2014.
- ^ Lombard Hill Group. "What Is Software Reuse?". Archived from the original on 23 January 2019. Retrieved 22 October 2014.
- ISBN 978-1-55615-900-8.
- ISBN 978-1-60558-286-3.
- ^ "Code reuse". DocForge. Archived from the original on 2011-07-10. Retrieved 5 April 2024.
- ^ ISBN 978-1-124-75297-6.
- ISBN 978-1-4503-0564-8. Archived from the original(PDF) on 2017-08-07. Retrieved 2017-08-07.
- ^ The Go Programming Language (2015-12-01), Go Proverbs – Rob Pike – Gopherfest – November 18, 2015, archived from the original on 2021-12-22, retrieved 26 February 2016