Version 11 of Techniques for making code reuse easier

Updated 2014-05-26 05:22:43 by pooryorick

Purpose: discuss techniques developers use to make code reuse easier.

  1. What is code reuse? Code reuse is one dream of some developers. It is the concept of writing code once, then using it in various other applications. In other industries (such as architecture, construction, automobile construction, food preparation) reuse of pre-constructed components is not only taken for granted, but critical for successful, safe construction.
  2. What makes code reuse hard? Noticing that the code needed is code already written. Remembering, or locating, the already written code. Finding code that was written in a manner so that it can be reused.
  3. Is code reuse really possible? Yes - Tcl is a prime example of code reuse.
  4. Is code reuse really practical? Yes, but it does take time, effort, and a desire to actually make the code reusable.
  5. What are techniques Tcl developers use to make code reuse easier?
    • The most important technique needed is the desire to actually use, and write, reusable code. Without that, nothing else will make significant impact.
    • Next, one must become aware of what code already has been written. There are large numbers of extensions that have already been written. However, there really isn't one single way to browse all of the code to determine what is available. Certainly many pages have been written on http://wiki.tcl.tk/ and at one time pages were available at http://www.tcl.tk/ and other sites attempting to catalog the extensions. And one can use any of the search engines covering large segments of development web sites, looking for discussions.
    • Once the preceeding techniques have been implemented, one needs to become aware, when designing code, of potential reusable components of the design. One then looks around to see if such components already exist. If so, then one makes use of them.
    • If a potentially reusable component is needed, but does not exist, then one is faced with the possibility of designing, implementing, and deploying a new component.

[Add details of things to consider when designing, implementing, and deploying new reusable components. Include design considerations, documentation, techniques to use and avoid when writing the code, and methods of distribution and advertising the new component.]


escargo 2006-04-08 : Two ways to facilitate code reuse are to ensure that the code in question is either incorporated as part of the core language (for us, something added with a TIP) or into a library that is likely distributed with the core (tcllib or tklib).


RJ 2006-04-09 - This page gave me an idea - I have two personal wikis going (one for work info, one for personal info). I have just set up a third one. I just went through all the 'utils' directory files and copy/pasted common pieces of code into categories. I was surprised how simple the categorization was. I think this will do it for me - next step is to go through all my tcl/tk apps and copy in all the great stuff I stole from Richard. Which by the way is a category of its own. ;)


NEM 2006-04-12 : Various approaches to programming have been proposed with the aim of increasing code reuse. Object orientation (OO) and Functional Programming are two such techniques. Writing code as a little language can also encourage reuse.


RS 2006-04-10 : My favorite code reuse technique is: put it on a Wiki page, with descriptive text that makes searching easier; when I need to reuse, locate it, drag over it with the mouse, paste into current project ;^)


MHo What makes reuse of code hard are the permanently changing programming environments and paradigms and OS-APIs (at least when using compiling languages in contrast to interpretative/runtime/virtual machine based development, especially in the MS-windows environment...). If using tcl with it's abstraction and good platform-independence it's not much a problem. Almost all old code is running with minimal changes over the time ;-)


2006-04-10 - The fundamental reason for considering code reuse could be seen as cost. The cost of developing code from scratch compared to the cost of finding and incorporating existing code that performs a particular function. There are lots of factors that are involved in the total costs of both alternatives. Code reuse has a lot of overhead costs because reusable code should be designed for reuse, must be stored where it can be found (which has a cost), and must be found (which also has a cost). On the plus side, proven code should have a lower defect rate (which avoids costs) and might take less time to get working than developing code from scratch (which should shorten a development cycle). As long as license issues are respected, open source code sharing can be a very good idea.

As the body of code that can be shared grows, finding the right piece to fit into a new development puzzle gets to be more difficult. This is a cost that is almost independent of the code; how are important features of the code described (functions, requirements, interfaces) and how do you take what you know about code that you want to find and then find it.

Once you find it, you need to determine how to combine it with your existing code. Designs for reusuable code need to avoid deep coupling (see Law of Demeter) to make program functions more modular. There are all kinds of wonderful issues to consider.