lib_guide.htm 20 KB

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