library_reuse.htm 4.4 KB

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