1# Bluetooth Documentation Style Guide 2This style guide is designed to encourage documentation that maximizes knowledge 3share and minimizes mental overhead. While this is technically only a 4documentation style guide, good code is self-documenting so there are many 5naming conventions stipulated that may result in code changes. 6 7## Acronyms, Abbreviations, and other shortenings 8 9Acronyms can often be confusing for those unfamiliar with them. At the same 10time, effective use of acronyms (and abbreviations) can help to quickly convey 11information compared to lengthy technical terms 12(e.g. `logicalLinkControlAndAdaptationLayerProtocol` takes substantially longer 13to read than `l2cap` and offers no additional clarity if the reader is familiar 14with the spec). To ensure effective use of these shorthands, follow the 15guidelines below. 16 171. Acronyms defined by the Bluetooth specification (e.g. `L2CAP`) may be used 18 anywhere, but the expanded version (e.g. "Logical Link Control and Adaptation 19 Layer") must be added to the [glossary](glossary.md) with an indication of 20 which specification document the reader can consult for more information. 21 * These acronyms may not be shortened in any context (i.e. `RFCOMM` may not 22 be shortened to `rfc`) 232. General computing shorthands (e.g. `tx` instead of `transmit`) are generally 24 allowed and should be added to the [glossary](glossary.md) depending on 25 obscurity at the discretion of code authors and reviewers. 26 * Recommended guideline for ascertaining obscurity: if the definition shows 27 up in the first five Google search results without any additional context 28 it is likely safe to leave it undocumented. Examples: 29 * `mux` is a very common shortening of “multiplexer” and shows up high on 30 search results so documenting is optional 31 * `fsm` is a common shortening of “finite state machine” but does not show 32 up high in search results and should be documented (not to be confused 33 with the Flying Spaghetti Monster which is the first result) 343. Acronyms and abbreviations specific to the codebase are generally 35 discouraged, but permitted and must be documented at the appropriate level of 36 specificity. 37 * Terms used across the codebase should be documented in the 38 [glossary](glossary.md) 39 * Terms used within specific files or directories only may be documented in 40 that file or directory 41 * Names of enums, structs, traits, files, etc. <b>must<b> be completely 42 spelled out (except for Bluetooth Specification acronyms) 434. In documentation files the first occurrence of ALL acronyms should be spelled 44 out. 45 * Example: you can refer to Three Letter Acronyms (TLAs) as simply TLAs in 46 the rest of the document 47 48## Citations 49 50Much of the logic within Floss is dictated by the Bluetooth 51Specification. Citing the individual sections of the specification that informed 52decisions makes it easier for the reader to understand why code is structured 53the way it is and aids debugging efforts. In general, any comments or 54explanations should be limited to the code’s structure (“the spec requires that 55this field be of length X”) and *not* why the specification makes certain 56requirements (“This field has a length of X to accommodate Y and Z with a parity 57bit as per the specification”) unless the code is directly related to those 58details (a parser for a field may benefit from having an explanation of the 59structure of the data it is meant to manipulate). 60 61In code: 62 63```cpp 64// This is the maximum allowed size for this field. 65// Bluetooth Core Specification Version 2.8, Volume 57, Part Z, Section 15 66``` 67 68In documentation (markdown): 69 70```md 71The order of these operations is required by the Bluetooth Core Spec[^ordering] 72 73[^ordering]: Bluetooth Core Specification Version 2.8, Volume 57, Part Z, Section 15 74``` 75 76## Top-of-file documentation 77 78All files should have a comment block preceding and code (except includes) which 79explains the purpose of the file and covers other meta-information that may be 80useful to a reader. There are no strict requirements for how this should be 81structured, but the following information should be covered. 82 831. A short summary of what is included in the file 842. Any relevant parts of the specification that the reader should be familiar 85 with 86 * It is not necessary to enumerate everything that might be relevant 87 * If the file primarily contains the implementation of a profile, it is 88 helpful to the reader to have a link to that specification 893. If the file is a “main” file as part of an executable it should contain 90 high-level information about: 91 * The purpose of the executable 92 * Usage information (unless the usage is self-documenting) 93 * Architectural overviews such as threading models and state machines 944. It is not necessary to go into details beyond what is needed for a reader to 95 be able to navigate the code. If something is necessary but is itself very 96 complex it is permissible to link to the documentation for that piece of 97 code. 98 * Example: an executable relies heavily on a complex state machine to 99 function, to the extent that anyone trying to read the code should be 100 familiar with it. The executable’s main file should have a short (less than 101 one paragraph) explanation of the state machine’s role and then link to the 102 file that contains the state machine (which should also be documented). 103 104## Dependency Documentation 105 106Whenever documentation depends on the reader understanding how a different 107system or code functions, prefer to write a brief description (1-2 sentences) of 108why that system is necessary or how it is being used, and leave details of the 109function of that system out. It is heavily encouraged to update a dependency's 110documentation as needed. 111 112## System Documentation 113 114Developers expect to find README files that explain the purpose of a given 115project and various meta-details about it. This can include build instructions 116or usage instructions, as well as information about how to contribute, and 117more. All of Floss’s binaries should have such information documented in a 118README file. Documentation authors have discretion to decide how much of this 119information belongs in a binary’s main file, a binary’s top-level directory, or 120in a project-level README. 121