CSC/ECE 517 Fall 2009/wiki2 7 co

From Expertiza_Wiki
Revision as of 22:42, 9 October 2009 by Jlmatloc (talk | contribs)
Jump to navigation Jump to search

Code Reuse Methods and Mechanisms

  The best way to attack the essence of building software is not to build it at all.
        - Fredrick P. Brooks, Jr.,The Mythical Man-Month

In his 1975 classic, The Mythical Man-Month, Fred Brooks claimed that the implementation of design (what he called "accidental tasks") was essentially efficient enough that improvements in that area would not result in significant gains in productivity. Twenty years later, in a follow-up edition, he refined and clarified his view. He recognized that the rise of object-oriented languages and methodologies had the potential and promise of easy reuse, although he was still skeptical of dramatic productivity claims. Fundamentally, though, he saw that overall software development productivity can be enhanced through reuse.

This page will review some of the different techniques that are available for code reuse, and then a comparison of the techniques will be presented.

Code Reuse Through Direct Code Use

There are several classic code reuse mechanisms which work at the fundamental source code level. This section will discuss this class of mechanisms.

Cut & Paste

One of the most basic reuse mechanism is the cut and paste method. Simply find the source code that performs the function that is required and copy the code into the place it is needed. This method can be implemented either by copying from some external source, such as a book or another software program, or by duplicating the same code within the same program. The latter method is generally a | very discouraged practice. Additionally, using this method can lead to | plagiarism.

Includes

In C and C++, the includes construct places the contents of the file specified in the include parameter in the spot where the include is placed:

  #include "time.h"
  class Time
  {...

In this example, the compiler effectively copies the code within time.h at the point where the #include statement is declared. Nearly all compilers will provide for specifying paths to search for the indicated file and provide rules or conventions for dealing with multiple occurrences of the same file.

Code Reuse through Subroutines

This section explores code reuse mechanisms that involve executing common blocks of code that can provide utility or common operations.

Gosub

blah

Procedures

blah

Functions

blah

Code Reuse through Extension

Many languages allow existing code to be reused through extensions that leave the original code unaltered. This section explores those mechanisms.

Methods

blah

Inheritance

blah

Polymorphism

blah

Generics

blah

Mixins/Modules

blah

Aspect

blah

Comparing the Various Mechanisms

Why Reuse Is Not Always Embraced

With all the various techniques available, code reuse is not universally embraced, either academically or commercially. What are the reasons for not reusing existing code?

  • Speed -
  • Lack of documentation -
  • Complexity -
  • Poor Design -
  • Licensing Issues -
  • Lack of Trust/Fear -

Conclusion

blah!

References