| [12] | 1 | <html> | 
|---|
 | 2 |  | 
|---|
 | 3 | <head> | 
|---|
 | 4 | <meta http-equiv="Content-Language" content="en-us"> | 
|---|
 | 5 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> | 
|---|
 | 6 | <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> | 
|---|
 | 7 | <meta name="ProgId" content="FrontPage.Editor.Document"> | 
|---|
 | 8 | <title>Boost Library Reuse</title> | 
|---|
 | 9 | </head> | 
|---|
 | 10 |  | 
|---|
 | 11 | <body bgcolor="#FFFFFF" text="#000000"> | 
|---|
 | 12 |  | 
|---|
 | 13 | <table border="1" bgcolor="#007F7F" cellpadding="2"> | 
|---|
 | 14 |   <tr> | 
|---|
 | 15 |     <td bgcolor="#FFFFFF"><img src="../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td> | 
|---|
 | 16 |     <td><a href="../index.htm"><font face="Arial" color="#FFFFFF"><big>Home</big></font></a></td> | 
|---|
 | 17 |     <td><a href="../libs/libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td> | 
|---|
 | 18 |     <td><a href="../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td> | 
|---|
 | 19 |     <td><a href="faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ</big></font></a></td> | 
|---|
 | 20 |     <td><a href="index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td> | 
|---|
 | 21 |   </tr> | 
|---|
 | 22 | </table> | 
|---|
 | 23 |   | 
|---|
 | 24 | <h1>Boost Library reuse: cost versus benefit trade-offs</h1> | 
|---|
 | 25 | <p>A Boost library <b>should not</b> use libraries other than Boost or the C++ | 
|---|
 | 26 | Standard Library.</p> | 
|---|
 | 27 | <p>A Boost library <b>should</b> use other Boost Libraries or the C++ Standard | 
|---|
 | 28 | Library, but only when the benefits outweigh the costs. </p> | 
|---|
 | 29 | <p>The benefits of using components from other libraries may include clearer, | 
|---|
 | 30 | more understandable code, reduced development and maintenance costs, and the | 
|---|
 | 31 | assurance which comes from reusing well-known and trusted building blocks.</p> | 
|---|
 | 32 | <p>The costs may include undesirable coupling between components, and added | 
|---|
 | 33 | compilation and runtime costs.  If the interface to the additional | 
|---|
 | 34 | component is complex, using it may make code less readable, and thus actually | 
|---|
 | 35 | increase development and maintenance costs.</p> | 
|---|
 | 36 | <p>Negative effects of coupling become obvious when one library uses a second | 
|---|
 | 37 | library which uses a third, and so on. The worst form of coupling requires the | 
|---|
 | 38 | user understand each of the coupled libraries. Coupling may also reduce the | 
|---|
 | 39 | portability of a library - even in case when all used libraries are | 
|---|
 | 40 | self-sufficient (see example of questionable usage of <iostream> library | 
|---|
 | 41 | below).</p> | 
|---|
 | 42 | <p><b>Example where another boost component should certainly be used:</b>  | 
|---|
 | 43 | boost::noncopyable (in <a href="../boost/utility.hpp">boost/utility.hpp</a>) has | 
|---|
 | 44 | considerable benefits; it simplifies code, improves readability, and signals | 
|---|
 | 45 | intent.  Costs are low as coupling is limited;  noncopyable itself | 
|---|
 | 46 | uses no other classes and its header includes only the lightweight headers | 
|---|
 | 47 | <boost/config.hpp> and <cstddef>.  There are no runtime costs | 
|---|
 | 48 | at all. With costs so low and benefits so high, other boost libraries should use | 
|---|
 | 49 | boost::noncopyable when the need arises except in exceptional circumstances.</p> | 
|---|
 | 50 | <p><b>Example where a standard library component might possibly be used:</b> | 
|---|
 | 51 | Providing diagnostic output as a debugging aid can be a nice feature for a | 
|---|
 | 52 | library. Yet using Standard Library <iostream> can involves a lot of | 
|---|
 | 53 | additional cost, particularly if <iostream> is unlikely to be use | 
|---|
 | 54 | elsewhere in the application.  In certain GUI or embedded applications, | 
|---|
 | 55 | coupling to <iostream> would be a disqualification.    | 
|---|
 | 56 | Consider redesign of the boost library in question so that the user supplies the | 
|---|
 | 57 | diagnostic output mechanism.</p> | 
|---|
 | 58 | <p><b>Example where another boost component should not be used:</b>  The | 
|---|
 | 59 | boost dir_it library has considerable coupling and runtime costs, not to mention | 
|---|
 | 60 | portability issues for unsupported operating systems.  While completely | 
|---|
 | 61 | appropriate when directory iteration is required, it would not be reasonable for | 
|---|
 | 62 | another boost library to use dir_it just to check that a file is available | 
|---|
 | 63 | before opening.  C++ Standard Library file open functionality does this at | 
|---|
 | 64 | lower cost.  Don't use dir_it just for the sake of using a boost library.</p> | 
|---|
 | 65 | <hr> | 
|---|
 | 66 | <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B %Y" startspan -->02 October 2003<!--webbot bot="Timestamp" endspan i-checksum="32277" --></p> | 
|---|
 | 67 | <p>© Copyright Beman Dawes 2000</p> | 
|---|
 | 68 | <p> Use, modification, and distribution are subject to the Boost Software  | 
|---|
 | 69 | License, Version 1.0. (See accompanying file <a href="../LICENSE_1_0.txt"> | 
|---|
 | 70 | LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> | 
|---|
 | 71 | www.boost.org/LICENSE_1_0.txt</a>)</p> | 
|---|
 | 72 |  | 
|---|
 | 73 | </body> | 
|---|
 | 74 |  | 
|---|
 | 75 | </html> | 
|---|