lib_guide.htm 32 KB

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