lib_guide.htm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Boost 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="../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. <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"><a name="Requirements">Requirements</a></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.
  31. </li>
  32. <li>The
  33. copyright <a href="#Ownership">ownership</a> must be clear.
  34. </li>
  35. <li>The library must be generally useful and not restricted to a narrow
  36. problem domain.
  37. </li>
  38. <li>The library must meet the <a href="#Portability">portability requirements</a>
  39. below.&nbsp;
  40. </li>
  41. <li>The library must come reasonably close to meeting the <a href="#Guidelines">Guidelines</a>
  42. below.
  43. <ul>
  44. <li><a href="#Design and Programming">Design and Programming</a></li>
  45. <li><a href="#Directory structure">Directory Structure</a></li>
  46. <li><a href="#Documentation">Documentation</a></li>
  47. </ul>
  48. </li>
  49. <li>The author must be willing to participate in discussions on the mailing
  50. list, and to refine the library accordingly.</li>
  51. </ul>
  52. <p>There's no requirement that an author read the mailing list for a time before
  53. making a submission. It has been noted, however, that submissions which begin
  54. &quot;I just started to read this mailing list ...&quot; seem to fail, often
  55. embarrassingly.</p>
  56. <h3 align="left"><a name="License">License</a> requirements</h3>
  57. <ul>
  58. <li>Must be simple to read and understand.
  59. </li>
  60. <li>Must grant permission to copy, use and modify the software for any use
  61. (commercial and non-commercial) for no fee.
  62. </li>
  63. <li>Must require that the license appear on all copies of the software source
  64. code.
  65. </li>
  66. <li>Must not require that the license appear with executables or other binary
  67. uses of the library.
  68. </li>
  69. <li>Must not require that the source code be
  70. available for execution or other binary uses of the library.
  71. </li>
  72. <li>May restrict the use of the name and description of the library to the
  73. standard version found on the Boost web site.</li>
  74. </ul>
  75. <h3 align="left"><a name="Portability">Portability</a> requirements</h3>
  76. <ul>
  77. <li>
  78. <p align="left">A library's interface must portable and not restricted to a
  79. particular compiler or operating system.
  80. </li>
  81. <li>
  82. <p align="left">A library's implementation must if possible be portable and
  83. not restricted to a particular compiler or operating system.&nbsp; If a
  84. portable implementation is not possible, non-portable constructions are
  85. acceptable if reasonably easy to port to other environments, and
  86. implementations are provided for at least two popular operating systems
  87. (such as UNIX and Windows).
  88. </li>
  89. <li>
  90. <p align="left">There is no requirement that a library run on C++ compilers
  91. which do not conform to the ISO standard.&nbsp;
  92. </li>
  93. <li>
  94. <p align="left">There is no requirement that a library run on any particular
  95. C++ compiler.&nbsp; Boost contributors often try to ensure their libraries
  96. work with popular compilers.&nbsp; The boost/config.hpp <a href="../libs/config/config.htm">configuration
  97. header</a> is the preferred mechanism for working around compiler
  98. deficiencies.</li>
  99. </ul>
  100. <p align="left">Since there is no absolute way to prove portability, many boost
  101. submissions demonstrate practical portability by compiling and executing
  102. correctly with two different C++ compilers, often under different operating
  103. systems.&nbsp; Otherwise reviewers may disbelieve that porting is in fact
  104. practical.</p>
  105. <h3 align="left"><a name="Ownership">Ownership</a></h3>
  106. <p align="left">Are you sure you own the library you are thinking of
  107. submitting?&nbsp;&nbsp; &quot;How to Copyright Software&quot; by MJ Salone, Nolo
  108. Press, 1990 says:</p>
  109. <blockquote>
  110. <p align="left">Doing work on your own time that is very similar to
  111. programming you do for your employer on company time can raise nasty legal
  112. problems.&nbsp; In this situation, it's best to get a written release from
  113. your employer in advance.</p>
  114. </blockquote>
  115. <p align="left">Place a copyright notice in all the important files you submit.
  116. Boost.org won't accept libraries without clear copyright information.</p>
  117. <h2 align="left"><a name="Guidelines">Guidelines</a></h2>
  118. <p align="left">Please use these guidelines as a checklist for preparing the
  119. content a library submission.&nbsp; Not every guideline applies to every
  120. library, but a reasonable effort to comply is expected.</p>
  121. <h3><a name="Design and Programming">Design and Programming</a></h3>
  122. <ul>
  123. <li>Aim first for clarity and correctness; optimization should be only a
  124. secondary concern in most Boost libraries.</li>
  125. </ul>
  126. <ul>
  127. <li>Aim for ISO Standard C++. Than means making effective use of the standard
  128. features of the language, and avoiding non-standard compiler extensions. It
  129. also means using the C++ Standard Library where applicable.</li>
  130. </ul>
  131. <ul>
  132. <li>Headers should be good neighbors. See the <a href="header.htm">header
  133. policy</a>.</li>
  134. </ul>
  135. <ul>
  136. <li>Follow quality programming practices. See, for example, &quot;Effective
  137. C++&quot; 2nd Edition, and &quot;More Effective C++&quot;, both by Scott
  138. Meyers, published by Addison Wesley.</li>
  139. </ul>
  140. <ul>
  141. <li>Use the C++ Standard Library or other Boost libraries, but only when the
  142. benefits outweigh the costs.&nbsp; Do not use libraries other than the C++
  143. Standard Library or Boost. See <a href="library_reuse.htm">Library reuse</a>.</li>
  144. </ul>
  145. <ul>
  146. <li>Read <a href="imp_vars.htm">Implementation Variation</a> to see how to
  147. supply performance, platform, or other implementation variations.</li>
  148. </ul>
  149. <ul>
  150. <li>Use the lowercase/underscore <a href="#Naming">naming conventions</a> of
  151. the C++ standard library.&nbsp; Template parameter names begin with an
  152. uppercase letter. Macro (gasp!) names should be all uppercase and begin with
  153. BOOST_.</li>
  154. </ul>
  155. <ul>
  156. <li>Choose meaningful names - explicit is better than implicit, and readability counts.
  157. There is a strong preference for clear and descriptive names, even if
  158. lengthy.</li>
  159. </ul>
  160. <ul>
  161. <li>Use exceptions to report errors where appropriate, and write code that is
  162. safe in the face of exceptions.</li>
  163. </ul>
  164. <ul>
  165. <li>Avoid exception-specifications. See <a href="#Exception-specification">exception-specification
  166. rationale</a>.</li>
  167. </ul>
  168. <ul>
  169. <li>Provide sample programs or confidence tests so potential users can see how
  170. to use your library.</li>
  171. </ul>
  172. <ul>
  173. <li>Provide a regression test program or programs which follow the <a href="test_policy.htm">Test
  174. Policies and Protocols</a>.</li>
  175. </ul>
  176. <ul>
  177. <li>Although some boost members use proportional fonts, tabs, and unrestricted
  178. line lengths in their own code, boost's widely distributed source code
  179. should follow more conservative guidelines:
  180. <ul>
  181. <li>Use fixed-width fonts.&nbsp; See <a href="#code fonts">fonts rationale</a>.</li>
  182. <li>Use spaces rather than tabs.</li>
  183. <li>Limit line lengths to 80 characters.</li>
  184. </ul>
  185. </li>
  186. </ul>
  187. <ul>
  188. <li>Begin all source files with:
  189. <ul>
  190. <li>A comment line describing the contents of the file.</li>
  191. <li>Comments describing copyright and licensing.</li>
  192. <li>A comment line referencing the Boost home page in the form:<br>
  193. <code>// See http://www.boost.org for updates, documentation, and
  194. revision history.</code><br>
  195. [Including revision history in source files is no longer recommended;
  196. the publicly available CVS repository better serves that purpose.]</li>
  197. </ul>
  198. </li>
  199. </ul>
  200. <h3><a name="Directory structure">Directory Structure</a> and Filenames</h3>
  201. <ul>
  202. <li>File and directory names must contain only lowercase ASCII letters ,
  203. numbers, underscores, and a period.&nbsp; Leading character must be
  204. alphabetic. Maximum length 31. Only a single period is permitted.&nbsp;
  205. These requirements ensure file and directory names are relatively portable.</li>
  206. <li>All libraries have at their highest level a primary directory named for
  207. the particular library. The primary directory may have sub-directories.</li>
  208. <li>For very simple libraries implemented entirely within the library header,
  209. all files go in the primary directory (except headers, which go in the boost
  210. header directory).</li>
  211. </ul>
  212. <blockquote>
  213. <p><b>Boost standard sub-directory names</b></p>
  214. <table border="1" cellpadding="5">
  215. <tr>
  216. <td><b>Sub-directory</b></td>
  217. <td><b>Contents</b></td>
  218. <td><b>Required</b></td>
  219. </tr>
  220. <tr>
  221. <td><code>build</code></td>
  222. <td>Library build files such as make files or IDE project files.</td>
  223. <td>If any build files.</td>
  224. </tr>
  225. <tr>
  226. <td>doc</td>
  227. <td>Documentation (HTML) files.</td>
  228. <td>If several doc files.</td>
  229. </tr>
  230. <tr>
  231. <td><code>example</code></td>
  232. <td>Sample program files.</td>
  233. <td>If several sample files.</td>
  234. </tr>
  235. <tr>
  236. <td><code>src</code></td>
  237. <td>Source files which must be compiled to build the library.&nbsp;</td>
  238. <td>If any source files.</td>
  239. </tr>
  240. <tr>
  241. <td><code>test</code></td>
  242. <td>Regression or other test programs or scripts.</td>
  243. <td>If several test files.</td>
  244. </tr>
  245. </table>
  246. </blockquote>
  247. <h3><a name="Documentation">Documentation</a></h3>
  248. <p>Even the simplest library needs some documentation; the amount should be
  249. proportional to the need.&nbsp; The documentation should assume the readers have
  250. a basic knowledge of C++, but are not necessarily experts.</p>
  251. <p>The format for documentation should be HTML, and should not require an
  252. advanced browser or server-side extensions.</p>
  253. <p>There is no single right way to do documentation. HTML documentation is often
  254. organized quite differently from traditional printed documents. Task-oriented
  255. styles differ from reference oriented styles. In the end, it comes down to the
  256. question: Is the documentation sufficient for the mythical &quot;average&quot;
  257. C++ programmer to use the library successfully?</p>
  258. <p>Appropriate topics for documentation often include:
  259. <ul>
  260. <li>General introduction to the library.</li>
  261. <li>Description of each class.</li>
  262. <li>Relationship between classes.</li>
  263. <li>For each function, as applicable, description, requirements
  264. (preconditions), effects, post-conditions, returns, and throws.</li>
  265. <li>Discussion of error detection and recovery strategy.</li>
  266. <li>How to use including description of typical uses.</li>
  267. <li>How to compile and link.</li>
  268. <li>How to test.</li>
  269. <li>Version or revision history.</li>
  270. <li>Rationale for design decisions.&nbsp; See <a href="#Rationale">Rationale
  271. rationale</a>.</li>
  272. <li>Acknowledgements.&nbsp; See <a href="#Acknowledgements">Acknowledgments
  273. rationale.</a></li>
  274. </ul>
  275. <h2>Rationale</h2>
  276. <p>Rationale for some of the requirements and guidelines follows.</p>
  277. <hr>
  278. <h3><a name="Exception-specification">Exception-specification</a> rationale</h3>
  279. <p>Exception specifications [ISO 15.4] are sometimes coded to indicate what
  280. exceptions may be thrown, or because the programmer hopes they will improved
  281. performance.&nbsp; But consider the following member from a smart pointer:</p>
  282. <pre> T&amp; operator*() const throw() { return *ptr; }</pre>
  283. <p>This function calls no other functions; it only manipulates fundamental data
  284. types like pointers Therefore, no runtime behavior of the
  285. exception-specification can ever be invoked.&nbsp; The function is completely
  286. exposed to the compiler; indeed it is declared inline Therefore, a smart
  287. compiler can easily deduce that the functions are incapable of throwing
  288. exceptions, and make the same optimizations it would have made based on the
  289. empty exception-specification. A &quot;dumb&quot; compiler, however, may make
  290. all kinds of pessimizations.</p>
  291. <p>For example, some compilers turn off inlining if there is an
  292. exception-specification.&nbsp; Some compilers add try/catch blocks. Such
  293. pessimizations can be a performance disaster which makes the code unusable in
  294. practical applications.</p>
  295. <p>Although initially appealing, an exception-specification tends to have
  296. consequences that require <b>very</b> careful thought to understand. The biggest
  297. problem with exception-specifications is that programmers use them as though
  298. they have the effect the programmer would like, instead of the effect they
  299. actually have.</p>
  300. <p>A non-inline function is the one place a &quot;throws nothing&quot;
  301. exception-specification may have some benefit with some compilers.</p>
  302. <hr>
  303. <h3><a name="Naming">Naming</a> conventions rationale</h3>
  304. <p>The C++ standard committee's Library Working Group discussed this issue in
  305. detail, and over a long period of time. The discussion was repeated again in
  306. early boost postings. A short summary:</p>
  307. <ul>
  308. <li>Naming conventions are contentious, and although several are widely used,
  309. no one style predominates.
  310. </li>
  311. <li>Given the intent to propose portions of boost for the next revision of the
  312. C++ standard library, boost decided to follow the standard library's
  313. conventions.
  314. </li>
  315. <li>Once a library settles on a particular convention, a vast majority of
  316. stakeholders want that style to be consistently used.
  317. </li>
  318. </ul>
  319. <hr>
  320. <h3>Source <a name="code fonts">code fonts</a> rationale</h3>
  321. <p>Dave Abrahams comments: An important purpose (I daresay the primary purpose)
  322. of source code is communication: the documentation of intent. This is a doubly
  323. important goal for boost, I think. Using a fixed-width font allows us to
  324. communicate with more people, in more ways (diagrams are possible) right there
  325. in the source. Code written for fixed-width fonts using spaces will read
  326. reasonably well when viewed with a variable-width font, and as far as I can tell
  327. every editor supporting variable-width fonts also supports fixed width. I don't
  328. think the converse is true.</p>
  329. <hr>
  330. <h3><a name="Rationale">Rationale</a> rationale</h3>
  331. <p>Rationale is defined as &quot;The fundamental reasons for something;
  332. basis.&quot; by the American Heritage Dictionary.</p>
  333. <p>Beman Dawes comments:&nbsp; Failure to supply contemporaneous rationale for
  334. design decisions is a major defect in many software projects. Lack of accurate
  335. rationale causes issues to revisited endlessly, causes maintenance bugs when a
  336. maintainer changes something without realizing it was done a certain way for
  337. some purpose, and shortens the useful lifetime of software.</p>
  338. <p>Rationale is fairly easy to provide at the time decisions are made, but very
  339. hard to accurately recover even a short time later.</p>
  340. <hr>
  341. <h3><a name="Acknowledgements">Acknowledgements</a> rationale</h3>
  342. <p>As a library matures, it almost always accumulates improvements suggested to
  343. the authors by other boost members.&nbsp; It is a part of the culture of
  344. boost.org to acknowledge such contributions, identifying the person making the
  345. suggestion.&nbsp; Major contributions are usually acknowledged in the
  346. documentation, while minor fixes are often mentioned in comments within the code
  347. itself.</p>
  348. <hr>
  349. <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 November, 2001<!--webbot bot="Timestamp" endspan i-checksum="39353" --></p>
  350. </body>
  351. </html>
粤ICP备19079148号