Purpose: discuss techniques developers use to make code reuse easier.
[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.