lib_guide.htm 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>
  5. Boost Library Requirements and Guidelines
  6. </title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  8. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  9. <meta name="ProgId" content="FrontPage.Editor.Document">
  10. <meta name="Microsoft Border" content="none, default">
  11. </head>
  12. <body bgcolor="#FFFFFF" text="#000000">
  13. <table border="1" bgcolor="#007F7F" cellpadding="2">
  14. <tr>
  15. <td bgcolor="#FFFFFF">
  16. <img src="../boost.png" alt="boost.png (6897 bytes)" width="277"
  17. height="86">
  18. </td>
  19. <td>
  20. <a href="../index.htm"><font face="Arial" color=
  21. "#FFFFFF"><big>Home</big></font></a>
  22. </td>
  23. <td>
  24. <a href="../libs/libraries.htm"><font face="Arial" color=
  25. "#FFFFFF"><big>Libraries</big></font></a>
  26. </td>
  27. <td>
  28. <a href="../people/people.htm"><font face="Arial" color=
  29. "#FFFFFF"><big>People</big></font></a>
  30. </td>
  31. <td>
  32. <a href="faq.htm"><font face="Arial" color=
  33. "#FFFFFF"><big>FAQ</big></font></a>
  34. </td>
  35. <td>
  36. <a href="index.htm"><font face="Arial" color=
  37. "#FFFFFF"><big>More</big></font></a>
  38. </td>
  39. </tr>
  40. </table>
  41. <h1 align="left">
  42. Boost Library Requirements and Guidelines
  43. </h1>
  44. <p align="left">
  45. <a href="#Introduction">Introduction</a><br>
  46. <a href="#Requirements">Requirements</a><br>
  47. &nbsp;&nbsp;&nbsp; <a href="#License">License requirements</a><br>
  48. &nbsp;&nbsp;&nbsp; <a href="#Portability">Portability requirements</a><br>
  49. &nbsp;&nbsp;&nbsp; <a href="#Ownership">Ownership</a><br>
  50. <a href="#Guidelines">Guidelines</a><br>
  51. &nbsp;&nbsp;&nbsp; <a href="#Design_and_Programming">Design and
  52. programming</a><br>
  53. &nbsp;&nbsp;&nbsp; <a href="#Directory_structure">Directory structure and
  54. filenames</a><br>
  55. &nbsp;&nbsp;&nbsp; <a href="#Naming_consistency">Naming
  56. consistency</a><br>
  57. &nbsp;&nbsp;&nbsp; <a href="#Documentation">Documentation</a><br>
  58. <a href="#Rationale">Rationale</a><br>
  59. &nbsp;&nbsp;&nbsp; <a href=
  60. "#Exception-specification">Exception-specification rationale</a><br>
  61. &nbsp;&nbsp;&nbsp; <a href="#Naming">Naming conventions rationale</a><br>
  62. &nbsp;&nbsp;&nbsp; <a href="#code_fonts">Source code fonts
  63. rationale</a><br>
  64. &nbsp;&nbsp;&nbsp; <a href="#Tabs">Tabs rationale</a><br>
  65. &nbsp;&nbsp;&nbsp; <a href="#JavaScript">ECMAScript/JavaScript
  66. rationale</a><br>
  67. &nbsp;&nbsp;&nbsp; <a href="#Rationale_rationale">Rationale
  68. rationale</a><br>
  69. &nbsp;&nbsp;&nbsp; <a href="#Acknowledgements">Acknowledgements
  70. rationale</a>
  71. </p>
  72. <h2 align="left">
  73. <a name="Introduction" id="Introduction">Introduction</a>
  74. </h2>
  75. <p align="left">
  76. This page describes requirements and guidelines for the content of a
  77. library submitted to Boost.
  78. </p>
  79. <p align="left">
  80. See the <a href="submission_process.htm">Boost Library Submission
  81. Process</a> page for a description of the process involved.
  82. </p>
  83. <h2 align="left">
  84. <a name="Requirements" id="Requirements">Requirements</a>
  85. </h2>
  86. <p>
  87. To avoid the frustration and wasted time of a proposed library being
  88. rejected, it must meets these requirements:
  89. </p>
  90. <ul>
  91. <li>The license must meet the <a href="#License">license requirements</a>
  92. below. Restricted licenses like the GPL and LGPL are not acceptable.
  93. </li>
  94. <li>The copyright <a href="#Ownership">ownership</a> must be clear.
  95. </li>
  96. <li>The library must be generally useful and not restricted to a narrow
  97. problem domain.
  98. </li>
  99. <li>The library must meet the <a href="#Portability">portability
  100. requirements</a> below.&nbsp;
  101. </li>
  102. <li>The library must come reasonably close to meeting the <a href=
  103. "#Guidelines">Guidelines</a> below.
  104. <ul>
  105. <li>
  106. <a href="#Design_and_Programming">Design and Programming</a>
  107. </li>
  108. <li>
  109. <a href="#Directory_structure">Directory Structure</a>
  110. </li>
  111. <li>
  112. <a href="#Documentation">Documentation</a>
  113. </li>
  114. </ul>
  115. </li>
  116. <li>The author must be willing to participate in discussions on the mailing
  117. list, and to refine the library accordingly.
  118. </li>
  119. </ul>
  120. <p>
  121. There's no requirement that an author read the mailing list for a time
  122. before making a submission. It has been noted, however, that submissions
  123. which begin "I just started to read this mailing list ..." seem to fail,
  124. often embarrassingly.
  125. </p>
  126. <h3 align="left">
  127. <a name="License" id="License">License</a> requirements
  128. </h3>
  129. <p>
  130. The preferred way to meet the license requirements is to use the <a href=
  131. "../LICENSE_1_0.txt">Boost Software License</a>. See <a href=
  132. "license_info.html">license information</a>. If for any reason you do not
  133. intend to use the Boost Software License, please discuss the issues on the
  134. Boost <a href="mailing_lists.htm#main">developers mailing list</a> first.
  135. </p>
  136. <p>
  137. The license requirements:
  138. </p>
  139. <ul>
  140. <li>Must be simple to read and understand.
  141. </li>
  142. <li>Must grant permission without fee to copy, use and modify the software
  143. for any use (commercial and non-commercial).
  144. </li>
  145. <li>Must require that the license appear on all copies of the software
  146. source code.
  147. </li>
  148. <li>Must not require that the license appear with executables or other
  149. binary uses of the library.
  150. </li>
  151. <li>Must not require that the source code be available for execution or
  152. other binary uses of the library.
  153. </li>
  154. <li>May restrict the use of the name and description of the library to the
  155. standard version found on the Boost web site.
  156. </li>
  157. </ul>
  158. <h3 align="left">
  159. <a name="Portability" id="Portability">Portability</a> requirements
  160. </h3>
  161. <ul>
  162. <li>
  163. <p align="left">
  164. A library's interface must portable and not restricted to a particular
  165. compiler or operating system.
  166. </p>
  167. </li>
  168. <li>
  169. <p align="left">
  170. A library's implementation must if possible be portable and not
  171. restricted to a particular compiler or operating system.&nbsp; If a
  172. portable implementation is not possible, non-portable constructions are
  173. acceptable if reasonably easy to port to other environments, and
  174. implementations are provided for at least two popular operating systems
  175. (such as UNIX and Windows).
  176. </p>
  177. </li>
  178. <li>
  179. <p align="left">
  180. There is no requirement that a library run on C++ compilers which do
  181. not conform to the ISO standard.&nbsp;
  182. </p>
  183. </li>
  184. <li>
  185. <p align="left">
  186. There is no requirement that a library run on any particular C++
  187. compiler.&nbsp; Boost contributors often try to ensure their libraries
  188. work with popular compilers.&nbsp; The boost/config.hpp <a href=
  189. "../libs/config/config.htm">configuration header</a> is the preferred
  190. mechanism for working around compiler deficiencies.
  191. </p>
  192. </li>
  193. </ul>
  194. <p align="left">
  195. Since there is no absolute way to prove portability, many boost submissions
  196. demonstrate practical portability by compiling and executing correctly with
  197. two different C++ compilers, often under different operating systems.&nbsp;
  198. Otherwise reviewers may disbelieve that porting is in fact practical.
  199. </p>
  200. <h3 align="left">
  201. <a name="Ownership" id="Ownership">Ownership</a>
  202. </h3>
  203. <p align="left">
  204. Are you sure you own the library you are thinking of
  205. submitting?&nbsp;&nbsp; "How to Copyright Software" by MJ Salone, Nolo
  206. Press, 1990 says:
  207. </p>
  208. <blockquote>
  209. <p align="left">
  210. Doing work on your own time that is very similar to programming you do
  211. for your employer on company time can raise nasty legal problems.&nbsp;
  212. In this situation, it's best to get a written release from your employer
  213. in advance.
  214. </p>
  215. </blockquote>
  216. <p align="left">
  217. Place a copyright notice in all the important files you submit. Boost won't
  218. accept libraries without clear copyright information.
  219. </p>
  220. <h2 align="left">
  221. <a name="Guidelines" id="Guidelines">Guidelines</a>
  222. </h2>
  223. <p align="left">
  224. Please use these guidelines as a checklist for preparing the content a
  225. library submission.&nbsp; Not every guideline applies to every library, but
  226. a reasonable effort to comply is expected.
  227. </p>
  228. <h3>
  229. <a name="Design_and_Programming" id="Design_and_Programming">Design and
  230. Programming</a>
  231. </h3>
  232. <ul>
  233. <li>Aim first for clarity and correctness; optimization should be only a
  234. secondary concern in most Boost libraries.
  235. </li>
  236. </ul>
  237. <ul>
  238. <li>Aim for ISO Standard C++. Than means making effective use of the
  239. standard features of the language, and avoiding non-standard compiler
  240. extensions. It also means using the C++ Standard Library where applicable.
  241. </li>
  242. </ul>
  243. <ul>
  244. <li>Headers should be good neighbors. See the <a href="header.htm">header
  245. policy</a>. See <a href="#Naming_consistency">Naming consistency</a>.
  246. </li>
  247. </ul>
  248. <ul>
  249. <li>Follow quality programming practices. See, for example, "Effective C++"
  250. 2nd Edition, and "More Effective C++", both by Scott Meyers, published by
  251. Addison Wesley.
  252. </li>
  253. </ul>
  254. <ul>
  255. <li>Use the C++ Standard Library or other Boost libraries, but only when
  256. the benefits outweigh the costs.&nbsp; Do not use libraries other than the
  257. C++ Standard Library or Boost. See <a href="library_reuse.htm">Library
  258. reuse</a>.
  259. </li>
  260. </ul>
  261. <ul>
  262. <li>Read <a href="imp_vars.htm">Implementation Variation</a> to see how to
  263. supply performance, platform, or other implementation variations.
  264. </li>
  265. </ul>
  266. <ul>
  267. <li>Read the <a href="separate_compilation.html">guidelines for libraries
  268. with separate source</a> to see how to ensure that compiled link libraries
  269. meet user expectations.
  270. </li>
  271. </ul>
  272. <ul>
  273. <li>Use the naming conventions of the C++ Standard Library (See <a href=
  274. "#Naming">Naming conventions rationale</a>):<br>
  275. &nbsp;
  276. <ul>
  277. <li>Names (except as noted below) should be all lowercase, with words
  278. separated by underscores.
  279. </li>
  280. <li>Acronyms should be treated as ordinary names (e.g.
  281. <code>xml_parser</code> instead of <code>XML_parser</code>).
  282. </li>
  283. <li>Template parameter names begin with an uppercase letter.
  284. </li>
  285. <li>Macro (gasp!) names all uppercase and begin with BOOST_.
  286. </li>
  287. </ul>
  288. </li>
  289. </ul>
  290. <ul>
  291. <li>Choose meaningful names - explicit is better than implicit, and
  292. readability counts. There is a strong preference for clear and descriptive
  293. names, even if lengthy.
  294. </li>
  295. </ul>
  296. <ul>
  297. <li>Use exceptions to report errors where appropriate, and write code that
  298. is safe in the face of exceptions.
  299. </li>
  300. </ul>
  301. <ul>
  302. <li>Avoid exception-specifications. See <a href="#Exception-specification">
  303. exception-specification rationale</a>.
  304. </li>
  305. </ul>
  306. <ul>
  307. <li>Provide sample programs or confidence tests so potential users can see
  308. how to use your library.
  309. </li>
  310. </ul>
  311. <ul>
  312. <li>Provide a regression test program or programs which follow the
  313. <a href="test_policy.htm">Test Policies and Protocols</a>.
  314. </li>
  315. </ul>
  316. <ul>
  317. <li>Although some boost members use proportional fonts, tabs, and
  318. unrestricted line lengths in their own code, boost's widely distributed
  319. source code should follow more conservative guidelines:
  320. <ul>
  321. <li>Use fixed-width fonts.&nbsp; See <a href="#code_fonts">fonts
  322. rationale</a>.
  323. </li>
  324. <li>Use spaces rather than tabs. See <a href="#Tabs">tabs
  325. rationale</a>.
  326. </li>
  327. <li>Limit line lengths to 80 characters.
  328. </li>
  329. </ul>
  330. </li>
  331. </ul>
  332. <ul>
  333. <li>End all documentation files (HTML or otherwise) with a copyright
  334. message and a licensing message. See <a href="license_info.html">license
  335. information</a> page for the preferred form.
  336. </li>
  337. </ul>
  338. <ul>
  339. <li>Begin all source files (including programs, headers, scripts, etc.)
  340. with:<br>
  341. &nbsp;
  342. <ul>
  343. <li>A comment line describing the contents of the file.<br>
  344. &nbsp;
  345. </li>
  346. <li>Comments describing copyright and licensing: again, the preferred
  347. form is indicated in the <a href="license_info.html">license
  348. information</a> page<br>
  349. <br>
  350. Note that developers should not provide a copy of
  351. <code>LICENSE_1_0.txt</code> with their libraries: Boost
  352. distributions already include a copy in the Boost root directory.<br>
  353. &nbsp;
  354. </li>
  355. <li>A comment line referencing your library on the Boost web site. For
  356. example:<br>
  357. <br>
  358. <code>//&nbsp; See http://www.boost.org/libs/foo/ for library home
  359. page.</code><br>
  360. <br>
  361. where <code>foo</code> is the directory name (see below) for the
  362. library. As well as aiding users who come across a Boost file
  363. detached from its documentation, some of Boost's automatic tools
  364. depend on this comment to identify which library header files belong
  365. to.
  366. </li>
  367. </ul>
  368. </li>
  369. </ul>
  370. <ul>
  371. <li>Make sure your code compiles in the presence of the <code>min()</code>
  372. and <code>max()</code> macros. Some platform headers define
  373. <code>min()</code> and <code>max()</code> macros which cause some common
  374. C++ constructs to fail to compile. Some simple tricks can protect your code
  375. from inappropriate macro substitution:<br>
  376. &nbsp;
  377. <ul>
  378. <li>If you want to call <code>std::min()</code> or
  379. <code>std::max()</code>:<br>
  380. &nbsp;
  381. <ul>
  382. <li>If you do not require argument-dependent look-up, use
  383. <code>(std::min)(a,b)</code>.
  384. </li>
  385. <li style="list-style: none">
  386. <br>
  387. </li>
  388. <li>If you do require argument-dependent look-up, you should:
  389. </li>
  390. <li style="list-style: none">
  391. <br>
  392. <ul>
  393. <li>
  394. <code>#include &lt;boost/config.hpp&gt;</code>
  395. </li>
  396. <li>Use <code>BOOST_USING_STD_MIN();</code> to bring
  397. <code>std::min()</code> into the current scope.
  398. </li>
  399. <li>Use <code>min BOOST_PREVENT_MACRO_SUBSTITUTION
  400. (a,b);</code> to make an argument-dependent call to
  401. <code>min(a,b)</code>.
  402. </li>
  403. </ul>
  404. </li>
  405. </ul>
  406. </li>
  407. <li style="list-style: none">
  408. <br>
  409. </li>
  410. <li>If you want to call
  411. <code>std::numeric_limits&lt;int&gt;::max()</code>, use
  412. <code>(std::numeric_limits&lt;int&gt;::max)()</code> instead.
  413. </li>
  414. <li style="list-style: none">
  415. <br>
  416. </li>
  417. <li>If you want to call a <code>min()</code> or <code>max()</code>
  418. member function, instead to doing <code>obj.min()</code>, use
  419. <code>(obj.min)()</code>.<br>
  420. </li>
  421. <li style="list-style: none">
  422. <br>
  423. </li>
  424. <li>If you want to declare or define a function or a member function
  425. named <code>min</code> or <code>max</code>, then you must use the
  426. <code>BOOST_PREVENT_MACRO_SUBSTITUTION</code> macro. Instead of writing
  427. <code>int min() { return 0; }</code> you should write <code>int min
  428. BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }</code><br>
  429. This is true regardless if the function is a free (namespace scope)
  430. function, a member function or a static member function, and it
  431. applies for the function declaration as well as for the function
  432. definition.<br>
  433. </li>
  434. </ul>
  435. </li>
  436. </ul>
  437. <h3>
  438. <a name="Directory_structure" id="Directory_structure">Directory
  439. Structure</a> and Filenames
  440. </h3>
  441. <ul>
  442. <li>File and directory names must contain only <b>lowercase</b> ASCII
  443. letters , numbers, underscores, and a period.&nbsp; Leading character must
  444. be alphabetic. Maximum length 31. Only a single period is permitted.&nbsp;
  445. These requirements ensure file and directory names are relatively portable.
  446. </li>
  447. <li>Files intended to be processed by a C++ compiler as part of a
  448. translation unit should have <b>a three-letter filename extension ending in
  449. "pp"</b>. Other files should <i>not</i> use extensions ending in "pp". This
  450. convention makes it easy to identify all of the C++ source in Boost.
  451. </li>
  452. <li>All libraries have at their highest level a primary directory named for
  453. the particular library. See <a href="#Naming_consistency">Naming
  454. consistency</a>. The primary directory may have sub-directories.
  455. </li>
  456. <li>For very simple libraries implemented entirely within the library
  457. header, all files go in the primary directory (except headers, which go in
  458. the boost header directory).
  459. </li>
  460. </ul>
  461. <blockquote>
  462. <p>
  463. <b>Boost standard sub-directory names</b>
  464. </p>
  465. <table border="1" cellpadding="5">
  466. <tr>
  467. <td>
  468. <b>Sub-directory</b>
  469. </td>
  470. <td>
  471. <b>Contents</b>
  472. </td>
  473. <td>
  474. <b>Required</b>
  475. </td>
  476. </tr>
  477. <tr>
  478. <td>
  479. <code>build</code>
  480. </td>
  481. <td>
  482. Library build files such as a Jamfile.
  483. </td>
  484. <td>
  485. If any build files.
  486. </td>
  487. </tr>
  488. <tr>
  489. <td>
  490. <code>doc</code>
  491. </td>
  492. <td>
  493. Documentation (HTML) files.
  494. </td>
  495. <td>
  496. If several doc files.
  497. </td>
  498. </tr>
  499. <tr>
  500. <td>
  501. <code>example</code>
  502. </td>
  503. <td>
  504. Sample program files.
  505. </td>
  506. <td>
  507. If several sample files.
  508. </td>
  509. </tr>
  510. <tr>
  511. <td>
  512. <code>src</code>
  513. </td>
  514. <td>
  515. Source files which must be compiled to build the library.&nbsp;
  516. </td>
  517. <td>
  518. If any source files.
  519. </td>
  520. </tr>
  521. <tr>
  522. <td>
  523. <code>test</code>
  524. </td>
  525. <td>
  526. Regression or other test programs or scripts.
  527. </td>
  528. <td>
  529. If several test files.
  530. </td>
  531. </tr>
  532. </table>
  533. </blockquote>
  534. <h4>
  535. <a name="Redirection" id="Redirection">Redirection</a>
  536. </h4>
  537. <p>
  538. The primary directory should always contain a file named index.html (or
  539. index.htm). Authors have requested this so that they can publish URL's in
  540. the form <i>http://www.boost.org/libs/lib-name</i> with the assurance a
  541. documentation reorganization won't invalidate the URL. Boost's internal
  542. tools are also simplified by knowing that a library's documentation is
  543. always reachable via the simplified URL.
  544. </p>
  545. <p>
  546. If the documentation is in a doc sub-directory, the primary directory
  547. index.html file should just do an automatic redirection to the doc
  548. subdirectory:
  549. </p>
  550. <blockquote>
  551. <pre>
  552. &lt;html&gt;
  553. &lt;head&gt;
  554. &lt;meta http-equiv="refresh" content="0; URL=doc/index.html"&gt;
  555. &lt;/head&gt;
  556. &lt;body&gt;
  557. Automatic redirection failed, please go to
  558. &lt;a href="doc/index.html"&gt;doc/index.html&lt;/a&gt;
  559. &lt;/body&gt;
  560. &lt;/html&gt;
  561. </pre>
  562. </blockquote>
  563. <h3>
  564. <a name="Naming_consistency">Naming consistency</a>
  565. </h3>
  566. <p>
  567. As library developers and users have gained experience with Boost, the
  568. following consistent naming approach has come to be viewed as very helpful,
  569. particularly for larger libraries that need their own header subdirectories
  570. and namespaces.
  571. </p>
  572. <p>
  573. Here is how it works. The library is given a name that describes the
  574. contents of the library. Cryptic abbreviations are strongly discouraged.
  575. Following the practice of the C++ Standard Library, names are usually
  576. singular rather than plural. For example, a library dealing with file
  577. systems might chose the name "filesystem", but not "filesystems", "fs" or
  578. "nicecode".
  579. </p>
  580. <ul>
  581. <li>The library's primary directory (in parent <i>boost-root/libs</i>) is
  582. given that same name.&nbsp; For example,
  583. <i>boost-root/libs/filesystem</i>.<br>
  584. &nbsp;
  585. </li>
  586. <li>The library's primary header directory (in parent
  587. <i>boost-root/boost</i>) is given that same name. For example,
  588. <i>boost-root/boost/filesystem</i>.<br>
  589. &nbsp;
  590. </li>
  591. <li>The library's primary namespace (in parent <i>::boost</i>) is given
  592. that same name, except when there's a component with that name (e.g.,
  593. <i>boost::tuple</i>), in which case the namespace name is pluralized. For
  594. example, <i>::boost::filesystem</i>.
  595. </li>
  596. </ul>
  597. <p>
  598. When documenting Boost libraries, follow these conventions (see also the
  599. following section of this document):
  600. </p>
  601. <ul>
  602. <li>The library name is set in roman type.
  603. </li>
  604. <li>The library name is capitalized.
  605. </li>
  606. <li>A period between "Boost" and the library name (e.g., Boost.Bind) is
  607. used if and only if the library name is not followed by the word "library".
  608. </li>
  609. <li>The word "library" is not part of the library name and is therefore
  610. lowercased.
  611. </li>
  612. </ul>
  613. <p>
  614. Here are a few examples of how to apply these conventions:
  615. </p>
  616. <ul>
  617. <li>Boost.Bind was written by Peter Dimov.
  618. </li>
  619. <li>The Boost Bind library was written by Peter Dimov.
  620. </li>
  621. <li>I regularly use Bind, a Boost library written by Peter Dimov.
  622. </li>
  623. </ul>
  624. <h3>
  625. <a name="Documentation" id="Documentation">Documentation</a>
  626. </h3>
  627. <p>
  628. Even the simplest library needs some documentation; the amount should be
  629. proportional to the need.&nbsp; The documentation should assume the readers
  630. have a basic knowledge of C++, but are not necessarily experts.
  631. </p>
  632. <p>
  633. The format for documentation should be HTML, and should not require an
  634. advanced browser or server-side extensions. Style sheets are acceptable.
  635. ECMAScript/JavaScript is not acceptable. The documentation entry point
  636. should always be a file named index.html or index.htm; see <a href=
  637. "#Redirection">Redirection</a>.
  638. </p>
  639. <p>
  640. There is no single right way to do documentation. HTML documentation is
  641. often organized quite differently from traditional printed documents.
  642. Task-oriented styles differ from reference oriented styles. In the end, it
  643. comes down to the question: Is the documentation sufficient for the
  644. mythical "average" C++ programmer to use the library successfully?
  645. </p>
  646. <p>
  647. Appropriate topics for documentation often include:
  648. </p>
  649. <ul>
  650. <li>General introduction to the library.
  651. </li>
  652. <li>Description of each class.
  653. </li>
  654. <li>Relationship between classes.
  655. </li>
  656. <li>For each function, as applicable, description, requirements
  657. (preconditions), effects, post-conditions, returns, and throws.
  658. </li>
  659. <li>Discussion of error detection and recovery strategy.
  660. </li>
  661. <li>How to use including description of typical uses.
  662. </li>
  663. <li>How to compile and link.
  664. </li>
  665. <li>How to test.
  666. </li>
  667. <li>Version or revision history.
  668. </li>
  669. <li>Rationale for design decisions.&nbsp; See <a href=
  670. "#Rationale">Rationale rationale</a>.
  671. </li>
  672. <li>Acknowledgements.&nbsp; See <a href="#Acknowledgements">Acknowledgments
  673. rationale.</a>
  674. </li>
  675. </ul>
  676. <p>
  677. If you need more help with how to write documentation you can check out the
  678. article on <a href="writingdoc/index.html">Writing Documentation for
  679. Boost</a>.
  680. </p>
  681. <h2>
  682. <a name="Rationale" id="Rationale">Rationale</a>
  683. </h2>
  684. <p>
  685. Rationale for some of the requirements and guidelines follows.
  686. </p>
  687. <hr>
  688. <h3>
  689. <a name="Exception-specification" id=
  690. "Exception-specification">Exception-specification</a> rationale
  691. </h3>
  692. <p>
  693. Exception specifications [ISO 15.4] are sometimes coded to indicate what
  694. exceptions may be thrown, or because the programmer hopes they will
  695. improved performance.&nbsp; But consider the following member from a smart
  696. pointer:
  697. </p>
  698. <pre>
  699. T&amp; operator*() const throw() { return *ptr; }
  700. </pre>
  701. <p>
  702. This function calls no other functions; it only manipulates fundamental
  703. data types like pointers Therefore, no runtime behavior of the
  704. exception-specification can ever be invoked.&nbsp; The function is
  705. completely exposed to the compiler; indeed it is declared inline Therefore,
  706. a smart compiler can easily deduce that the functions are incapable of
  707. throwing exceptions, and make the same optimizations it would have made
  708. based on the empty exception-specification. A "dumb" compiler, however, may
  709. make all kinds of pessimizations.
  710. </p>
  711. <p>
  712. For example, some compilers turn off inlining if there is an
  713. exception-specification.&nbsp; Some compilers add try/catch blocks. Such
  714. pessimizations can be a performance disaster which makes the code unusable
  715. in practical applications.
  716. </p>
  717. <p>
  718. Although initially appealing, an exception-specification tends to have
  719. consequences that require <b>very</b> careful thought to understand. The
  720. biggest problem with exception-specifications is that programmers use them
  721. as though they have the effect the programmer would like, instead of the
  722. effect they actually have.
  723. </p>
  724. <p>
  725. A non-inline function is the one place a "throws nothing"
  726. exception-specification may have some benefit with some compilers.
  727. </p>
  728. <hr>
  729. <h3>
  730. <a name="Naming" id="Naming">Naming</a> conventions rationale
  731. </h3>
  732. <p>
  733. The C++ standard committee's Library Working Group discussed this issue in
  734. detail, and over a long period of time. The discussion was repeated again
  735. in early boost postings. A short summary:
  736. </p>
  737. <ul>
  738. <li>Naming conventions are contentious, and although several are widely
  739. used, no one style predominates.
  740. </li>
  741. <li>Given the intent to propose portions of boost for the next revision of
  742. the C++ standard library, boost decided to follow the standard library's
  743. conventions.
  744. </li>
  745. <li>Once a library settles on a particular convention, a vast majority of
  746. stakeholders want that style to be consistently used.
  747. </li>
  748. </ul>
  749. <hr>
  750. <h3>
  751. Source <a name="code_fonts" id="code_fonts">code fonts</a> rationale
  752. </h3>
  753. <p>
  754. Dave Abrahams comments: An important purpose (I daresay the primary
  755. purpose) of source code is communication: the documentation of intent. This
  756. is a doubly important goal for boost, I think. Using a fixed-width font
  757. allows us to communicate with more people, in more ways (diagrams are
  758. possible) right there in the source. Code written for fixed-width fonts
  759. using spaces will read reasonably well when viewed with a variable-width
  760. font, and as far as I can tell every editor supporting variable-width fonts
  761. also supports fixed width. I don't think the converse is true.
  762. </p>
  763. <hr>
  764. <h3>
  765. <a name="Tabs" id="Tabs">Tabs</a> rationale
  766. </h3>
  767. <p>
  768. Tabs are banned because of the practical problems caused by tabs in
  769. multi-developer projects like Boost, rather than any dislike in principle.
  770. See <a href="mailing_lists.htm#archive">mailing list archives</a>. Problems
  771. include maintenance of a single source file by programmers using tabs and
  772. programmers using spaces, and the difficulty of enforcing a consistent tab
  773. policy other than just "no tabs". Discussions concluded that Boost files
  774. should either all use tabs, or all use spaces, and thus the decision to
  775. stick with spaces.
  776. </p>
  777. <hr>
  778. <h3>
  779. ECMAScript/<a name="JavaScript" id="JavaScript">JavaScript</a> rationale
  780. </h3>
  781. <p>
  782. Before the 1.29.0 release, two Boost libraries added ECMAScript/JavaScript
  783. documentation. Controversy followed (see <a href=
  784. "mailing_lists.htm#archive">mailing list archives</a>), and the developers
  785. were asked to remove the ECMAScript/JavaScript. Reasons given for banning
  786. included:
  787. </p>
  788. <ul>
  789. <li>Incompatible with some older browsers and some text based browsers.
  790. </li>
  791. <li>Makes printing docs pages difficult.
  792. </li>
  793. <li>Often results in really bad user interface design.
  794. </li>
  795. <li>"It's just annoying in general."
  796. </li>
  797. <li>Would require Boost to test web pages for ECMAScript/JavaScript
  798. compliance.
  799. </li>
  800. <li>Makes docs maintenance by other than the original developer more
  801. difficult.
  802. </li>
  803. </ul>
  804. <hr>
  805. <h3>
  806. <a name="Rationale_rationale" id="Rationale_rationale">Rationale
  807. rationale</a>
  808. </h3>
  809. <p>
  810. Rationale is defined as "The fundamental reasons for something; basis" by
  811. the American Heritage Dictionary.
  812. </p>
  813. <p>
  814. Beman Dawes comments:&nbsp; Failure to supply contemporaneous rationale for
  815. design decisions is a major defect in many software projects. Lack of
  816. accurate rationale causes issues to be revisited endlessly, causes
  817. maintenance bugs when a maintainer changes something without realizing it
  818. was done a certain way for some purpose, and shortens the useful lifetime
  819. of software.
  820. </p>
  821. <p>
  822. Rationale is fairly easy to provide at the time decisions are made, but
  823. very hard to accurately recover even a short time later.
  824. </p>
  825. <hr>
  826. <h3>
  827. <a name="Acknowledgements" id="Acknowledgements">Acknowledgements</a>
  828. rationale
  829. </h3>
  830. <p>
  831. As a library matures, it almost always accumulates improvements suggested
  832. to the authors by other boost members.&nbsp; It is a part of the culture of
  833. boost.org to acknowledge such contributions, identifying the person making
  834. the suggestion.&nbsp; Major contributions are usually acknowledged in the
  835. documentation, while minor fixes are often mentioned in comments within the
  836. code itself.
  837. </p>
  838. <hr>
  839. <p>
  840. Revised
  841. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->
  842. 04 November, 2003<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
  843. </p>
  844. <p>
  845. &copy; <a name="Copyright" id="Copyright">Copyright</a> Beman Dawes 2003.
  846. </p>
  847. <p>
  848. Distributed under the Boost Software License, Version 1.0. (See
  849. accompanying file <a href="../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
  850. at <a href=
  851. "http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)
  852. </p>
  853. </body>
  854. </html>
粤ICP备19079148号