lib_guide.htm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Library Requirements and Guidelines</title>
  5. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  6. <meta name="ProgId" content="FrontPage.Editor.Document">
  7. <meta name="Microsoft Border" content="none, default">
  8. </head>
  9. <body bgcolor="#FFFFFF" text="#000000">
  10. <table border="1" bgcolor="#007F7F" cellpadding="2">
  11. <tr>
  12. <td bgcolor="#FFFFFF"><img src="../c++boost.gif" alt="c++boost.gif (8819 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="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
  15. <td><a href="../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. <h1 align="left">Boost Library Requirements and Guidelines</h1>
  21. <p align="left">This page describes requirements and guidelines for the content
  22. of a library submitted to Boost.</p>
  23. <p align="left">See the <a href="submission_process.htm">Boost Library
  24. Submission Process</a> page for a description of the process involved.</p>
  25. <h2 align="left">Requirements</h2>
  26. <p>To avoid the frustration and wasted time of a proposed library being
  27. rejected, it must meets these requirements:</p>
  28. <ul>
  29. <li>The license must meet the <a href="#License">license requirements</a>
  30. below. Restricted licenses like the GPL and LGPL are not acceptable. The
  31. copyright <a href="#Ownership">ownership</a> must be clear.<br>
  32. </li>
  33. <li>The library must be generally useful and not restricted to a narrow
  34. problem domain.<br>
  35. </li>
  36. <li>The library must meet the <a href="#Portability">portability requirements</a>
  37. below.&nbsp;<br>
  38. </li>
  39. <li>The library must come reasonably close to meeting the <a href="#Guidelines">Guidelines</a>
  40. below.<br>
  41. </li>
  42. <li>The author must be willing to participate in discussions on the mailing
  43. list, and to refine the library accordingly.</li>
  44. </ul>
  45. <p>There's no requirement that an author read the mailing list for a time before
  46. making a submission. It has been noted, however, that submissions which begin
  47. &quot;I just started to read this mailing list ...&quot; seem to fail, often
  48. embarrassingly.</p>
  49. <h3 align="left"><a name="License">License</a> requirements</h3>
  50. <ul>
  51. <li>Must be simple to read and understand.<br>
  52. </li>
  53. <li>Must grant permission to copy, use and modify the software for any use
  54. (commercial and non-commercial) for no fee.<br>
  55. </li>
  56. <li>Must require that the license appear on all copies of the software source
  57. code.<br>
  58. </li>
  59. <li>Must not require that the license appear with executables or other binary
  60. uses of the library.&nbsp;&nbsp; Must not require that the source code be
  61. available for execution or other binary uses of the library.<br>
  62. </li>
  63. <li>May restrict the use of the name and description of the library to the
  64. standard version found on the Boost web site.</li>
  65. </ul>
  66. <h3 align="left"><a name="Portability">Portability</a> requirements</h3>
  67. <ul>
  68. <li>
  69. <p align="left">A library's interface must portable and not restricted to a
  70. particular compiler or operating system.<br>
  71. </li>
  72. <li>
  73. <p align="left">A library's implementation must if possible be portable and
  74. not restricted to a particular compiler or operating system.&nbsp; If a
  75. portable implementation is not possible, non-portable constructions are
  76. acceptable if reasonably easy to port to other environments.<br>
  77. </li>
  78. <li>
  79. <p align="left">There is no requirement that a library run on all C++
  80. compilers.&nbsp;&nbsp;<br>
  81. </li>
  82. <li>
  83. <p align="left">There is no requirement that a library run on any particular
  84. C++ compiler.&nbsp; Boost contributors often try to ensure their libraries
  85. work with popular compilers.&nbsp; The boost/config.hpp <a href="../libs/config/index.htm">configuration
  86. header</a> is the preferred mechanism for working around compiler
  87. deficiencies.</li>
  88. </ul>
  89. <p align="left">Since there is no absolute way to prove portability, many boost
  90. submissions demonstrate practical portability by compiling and executing
  91. correctly with two different C++ compilers, often under different operating
  92. systems.&nbsp; Otherwise reviewers may disbelieve that porting is in fact
  93. practical.</p>
  94. <h3 align="left"><a name="Ownership">Ownership</a></h3>
  95. <p align="left">Are you sure you own the library you are thinking of
  96. submitting?&nbsp;&nbsp; &quot;How to Copyright Software&quot; by MJ Salone, Nolo
  97. Press, 1990 says:</p>
  98. <blockquote>
  99. <p align="left">Doing work on your own time that is very similar to
  100. programming you do for your employer on company time can raise nasty legal
  101. problems.&nbsp; In this situation, it's best to get a written release from
  102. your employer in advance.</p>
  103. </blockquote>
  104. <p align="left">Place a copyright notice in all the important files you submit.
  105. Boost.org won't accept libraries without clear copyright information.</p>
  106. <h2 align="left"><a name="Guidelines">Guidelines</a></h2>
  107. <p align="left">Please use these guidelines as a checklist for preparing the
  108. content a library submission.&nbsp; Not every guideline applies to every
  109. library, but a reasonable effort to comply is expected.</p>
  110. <h3>Design and Programming</h3>
  111. <ul>
  112. <li>Aim for ISO Standard C++. Than means making effective use of the standard
  113. features of the language, and avoiding non-standard compiler extensions. It
  114. also means using the C++ Standard Library where applicable.</li>
  115. </ul>
  116. <ul>
  117. <li>Headers should be good neighbors. See the <a href="header.htm">header
  118. policy</a>.</li>
  119. </ul>
  120. <ul>
  121. <li>Follow the <a href="imp_vars.htm">implementation variation policy</a>.&nbsp;</li>
  122. </ul>
  123. <ul>
  124. <li>Follow quality programming practices. See, for example, &quot;Effective
  125. C++&quot; 2nd Edition, and &quot;More Effective C++&quot;, both by Scott
  126. Meyers, published by Addison Wesley.</li>
  127. </ul>
  128. <ul>
  129. <li>Use the lowercase/underscore <a href="#Naming">naming conventions</a> of
  130. the C++ standard library.&nbsp; Template parameter names begin with an
  131. uppercase letter. Macro (gasp!) names should be all uppercase and begin with
  132. BOOST_.</li>
  133. </ul>
  134. <ul>
  135. <li>Use exceptions to report errors where appropriate, and write code that is
  136. safe in the face of exceptions.</li>
  137. </ul>
  138. <ul>
  139. <li>Avoid exception-specifications. See <a href="#Exception-specification">exception-specification
  140. rationale</a>.</li>
  141. </ul>
  142. <ul>
  143. <li>Provide sample programs, confidence tests, or regression tests so
  144. potential users can see how to use your library and verify that it has
  145. compiled correctly.</li>
  146. </ul>
  147. <ul>
  148. <li>Although some boost members use proportional fonts, tabs, and unrestricted
  149. line lengths in their own code, boost's widely distributed source code
  150. should follow more conservative guidelines:
  151. <ul>
  152. <li>Use fixed-width fonts.&nbsp; See <a href="#code fonts">fonts rationale</a>.</li>
  153. <li>Use spaces rather than tabs.</li>
  154. <li>Limit line lengths to 80 characters.</li>
  155. </ul>
  156. </li>
  157. </ul>
  158. <h3>Documentation</h3>
  159. <p>Even the simplest library needs some documentation; the amount should be
  160. proportional to the need.&nbsp; The documentation should assume the readers have
  161. a basic knowledge of C++, but are not necessarily experts.</p>
  162. <p>The format for documentation should be HTML, and should not require an
  163. advanced browser or server-side extensions.</p>
  164. <p>There is no single right way to do documentation. HTML documentation is often
  165. organized quite differently from traditional printed documents. Task-oriented
  166. styles differ from reference oriented styles. In the end, it comes down to the
  167. question: Is the documentation sufficient for the mythical &quot;average&quot;
  168. C++ programmer to use the library successfully?</p>
  169. <p>Appropriate topics for documentation often include:
  170. <ul>
  171. <li>General introduction to the library.</li>
  172. <li>Description of each class.</li>
  173. <li>Relationship between classes.</li>
  174. <li>For each function, as applicable, description, requirements
  175. (preconditions), effects, post-conditions, returns, and throws.</li>
  176. <li>Discussion of error detection and recovery strategy.</li>
  177. <li>How to use including description of typical uses.</li>
  178. <li>How to compile and link.</li>
  179. <li>How to test.</li>
  180. <li>Version or revision history.</li>
  181. <li>Rationale for design decisions.&nbsp; See <a href="#Rationale">Rationale
  182. rationale</a>.</li>
  183. <li>Acknowledgements.&nbsp; See <a href="#Acknowledgements">Acknowledgments
  184. rationale.</a></li>
  185. </ul>
  186. <h2>Rationale</h2>
  187. <p>Rationale for some of the requirements and guidelines follows.</p>
  188. <h3><a name="Exception-specification">Exception-specification</a> rationale</h3>
  189. <p>Exception specifications [ISO 15.4] are sometimes coded to indicate what
  190. exceptions may be thrown, or because the programmer hopes they will improved
  191. performance.&nbsp; But consider the follow member from a smart pointer:</p>
  192. <pre> T&amp; operator*() const throw() { return *ptr; }</pre>
  193. <p>This function calls no other functions; it only manipulates fundamental data
  194. types like pointers Therefore, no runtime behavior of the
  195. exception-specification can ever be invoked.&nbsp; The function is completely
  196. exposed to the compiler; indeed it is declared inline Therefore, a smart
  197. compiler can easily deduce that the functions are incapable of throwing
  198. exceptions, and make the same optimizations it would have made based on the
  199. empty exception-specification. A &quot;dumb&quot; compiler, however, may make
  200. all kinds of pessimizations.</p>
  201. <p>For example, some compilers turn off inlining if there is an
  202. exception-specification.&nbsp; Some compilers add try/catch blocks. Such
  203. pessimizations can be a performance disaster which makes the code unusable in
  204. practical applications.</p>
  205. <p>Although initially appealing, an exception-specification tends to have
  206. consequences that require <b>very</b> careful thought to understand. The biggest
  207. problem with exception-specifications is that programmers use them as though
  208. they have the effect the programmer would like, instead of the effect they
  209. actually have.</p>
  210. <p>A non-inline function is the one place a &quot;throws nothing&quot;
  211. exception-specification may have some benefit with some compilers.</p>
  212. <hr>
  213. <h3><a name="Naming">Naming</a> conventions rationale</h3>
  214. <p>The C++ standard committee's Library Working Group discussed this issue in
  215. detail, and over a long period of time. The discussion was repeated again in
  216. early boost postings. A short summary:</p>
  217. <ul>
  218. <li>Naming conventions are contentious, and although several are widely used,
  219. no one style predominates.<br>
  220. </li>
  221. <li>Given the intent to propose portions of boost for the next revision of the
  222. C++ standard library, boost decided to follow the standard library's
  223. conventions.<br>
  224. </li>
  225. <li>Once a library settles on a particular convention, a vast majority of
  226. stakeholders want that style to be consistently used.<br>
  227. </li>
  228. <li>There is a strong preference for clear and descriptive names, even if
  229. lengthy.</li>
  230. </ul>
  231. <hr>
  232. <h3>Source <a name="code fonts">code fonts</a> rationale</h3>
  233. <p>Dave Abrahams comments: An important purpose (I daresay the primary purpose)
  234. of source code is communication: the documentation of intent. This is a doubly
  235. important goal for boost, I think. Using a fixed-width font allows us to
  236. communicate with more people, in more ways (diagrams are possible) right there
  237. in the source. Code written for fixed-width fonts using spaces will read
  238. reasonably well when viewed with a variable-width font, and as far as I can tell
  239. every editor supporting variable-width fonts also supports fixed width. I don't
  240. think the converse is true.</p>
  241. <hr>
  242. <h3><a name="Rationale">Rationale</a> rationale</h3>
  243. <p>Rationale is defined as &quot;The fundamental reasons for something;
  244. basis.&quot; by the American Heritage Dictionary.</p>
  245. <p>Beman Dawes comments:&nbsp; Failure to supply contemporaneous rationale for
  246. design decisions is a major defect in many software projects. Lack of accurate
  247. rationale causes issues to revisited endlessly, causes maintenance bugs when a
  248. maintainer changes something without realizing it was done a certain way for
  249. some purpose, and shortens the useful lifetime of software.</p>
  250. <p>Rationale is fairly easy to provide at the time decisions are made, but very
  251. hard to accurately recover even a short time later.</p>
  252. <hr>
  253. <h3><a name="Acknowledgements">Acknowledgements</a> rationale</h3>
  254. <p>As a library matures, it almost always accumulates improvements suggested to
  255. the authors by other boost members.&nbsp; It is a part of the culture of
  256. boost.org to acknowledge such contributions, identifying the person making the
  257. suggestion.&nbsp; Major contributions are usually acknowledged in the
  258. documentation, while minor fixes are often mentioned in comments within the code
  259. itself.</p>
  260. <hr>
  261. <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->24 July, 2000<!--webbot bot="Timestamp" endspan i-checksum="21054" --></p>
  262. </body>
  263. </html>
粤ICP备19079148号