Skip to content

Commit 650febe

Browse files
author
Will Binns
committed
docs: Add style guide
1 parent 7c77916 commit 650febe

File tree

1 file changed

+349
-0
lines changed

1 file changed

+349
-0
lines changed

docs/style-guide.md

Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
1+
# Style Guide
2+
3+
For better consistency, this style guide can be used as a reference for
4+
terminology, style and formatting. Suggested changes can also be submitted to
5+
this guide to keep it up to date.
6+
7+
Below are a series of guidelines, with some parts being mandatory and other
8+
parts being only advisory. You do not need to read it before contributing---the
9+
people reviewing your pull request will let you know if you break any important
10+
rules.
11+
12+
For all style matters not explicitly covered in this guide, the authority is the
13+
[Wikipedia Manual Of
14+
Style](http://en.wikipedia.org/wiki/Wikipedia%3aManual_of_Style).
15+
16+
## Audience Description
17+
18+
Readers will primarily use this guide to build applications that are
19+
interoperable with Bitcoin. Therefore, the reader knows at least one
20+
full-featured programming language fairly well, including standard programming
21+
jargon, and will have received and sent at least one Bitcoin transaction using a
22+
common wallet application.
23+
24+
Readers will have read programming books before, so they will be prepared to
25+
skim over sections of examples and technical data during their first read, and
26+
will return to those sections of the guide when they need those details for
27+
implementation.
28+
29+
Readers are not expected to be an expert in any system used by Bitcoin, such as
30+
cryptographic hashing, cryptographic signing, peer-to-peer networking, stack
31+
programming, remote procedure calls, etc. However, readers who do know about
32+
these things will get bored if they must read a lengthy description of them, so
33+
brief descriptions or easy skimming should be emphasized.
34+
35+
Finally, readers are expected to be motivated to learn, so they do not need to
36+
be entertained or otherwise motivated to keep reading; it is enough to give them
37+
the facts as quickly as possible.
38+
39+
## Code formatting
40+
41+
To make this document easier to read, text inside code blocks should be modified
42+
as follows:
43+
44+
**Shortening strings**: Inside a string, bracket-ellipsis-bracket indicates a
45+
range of consecutive non-whitespace characters were omitted. For example, the
46+
hash of an empty string is e3b0[...]b855.
47+
48+
**Shortening lists**: On a line by itself, bracket-ellipsis-bracket indicates a
49+
range of consecutive lines were omitted. For example:
50+
51+
~~~
52+
$ seq 1 5
53+
1
54+
2
55+
[...]
56+
5
57+
~~~
58+
59+
**Splitting large strings**: When long strings are shown in their entirety,
60+
backslash-newline indicates a single string has been printed across multiple
61+
lines. For example, this is the full version of the first standard transaction
62+
ever made:
63+
64+
~~~
65+
0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25\
66+
857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f\
67+
4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd1290\
68+
9d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b0000000043\
69+
4104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa2\
70+
8414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6c\
71+
d84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a\
72+
382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b\
73+
64f9d4c03f999b8643f656b412a3ac00000000
74+
~~~
75+
76+
Try to wrap lines after the 64th character, as shown in the example above.
77+
However, lines of up to 76 characters seem to render correctly in the current
78+
layout, so longer lines are tolerable. When possible, editors should try to
79+
format code so that the bottom scrollbar doesn't appear in the code block.
80+
81+
**Code Before Descriptions:** when long code blocks are broken up to allow
82+
explanations in HTML paragraphs, the code fragment should come before the
83+
explanation. For example:
84+
85+
~~~
86+
> echo "Hello, World!"
87+
~~~
88+
89+
Although the command above works in POSIX shell, it doesn't work as expected in
90+
the bash shell because the `!` (bang) character has special meaning.
91+
92+
~~~
93+
> echo 'Hello, World!'
94+
~~~~
95+
96+
When the bang character is used, it should be escaped or placed in single quotes
97+
to ensure it is interpreted literally.
98+
99+
*References:* the shortening and spiting conventions were discussed in [an old pull
100+
request](https://github.com/saivann/bitcoin.org/pull/11). Placing code
101+
before descriptions was discussed in another [old pull
102+
request](https://github.com/saivann/bitcoin.org/pull/74).
103+
104+
## Style
105+
106+
### Capitalization In Headings, Subheads, Captions, And Abbreviation Expansions
107+
108+
The first letter of each word in headings, subheadings, captions, and
109+
abbreviation expansions should be capitalized---this includes
110+
prepositions.
111+
112+
* Heading/Subhead: "Capitalization In Headings, [...]"
113+
* Captions: "Some Of The Data Signed By Default"
114+
* Abbreviation Expansions: "Pay To PubKey Hash (P2PKH)"
115+
116+
*References:* this style was used without discussion since the first
117+
section of the guide was written and is currently being used to avoid
118+
a major revision for a minor issue. Some discussion was held in [pull
119+
request #589](https://github.com/bitcoin-dot-org/bitcoin.org/pull/589#discussion-diff-18306278),
120+
but a real discussion should be held about changing this before any
121+
major revision of the docs.
122+
123+
### First Paragraphs
124+
125+
The first paragraph of an header-level-2 (h2) section in the developer
126+
guide should briefly describe the topic. Subsections do not need to
127+
follow this format, but it wouldn't hurt.
128+
129+
### Linking
130+
131+
All links should use Markdown-style reference links, for example:
132+
133+
~~~
134+
My favorite Bitcoin library is [bitcoinj].
135+
~~~
136+
137+
Specifically:
138+
139+
~~~
140+
[bitcoinj]: http://bitcoinj.org/
141+
~~~
142+
143+
### Hex
144+
145+
Hexadecimal byte strings should always be prefixed by "0x" and should be
146+
in lowercase. They should otherwise be treated like regular words, such
147+
as adding punctuation after them. For example: 0x0123456789abcdef.
148+
The should not be put inside `code` spans or blocks unless representing
149+
literal program input or output.
150+
151+
Long hex strings may be broken apart on byte boundaries to improve
152+
readability. For example: 0x0123 4567 89ab cdef.
153+
154+
Exception: program output or input should be in whatever format the
155+
program uses.
156+
157+
158+
### References
159+
160+
**Internal Figures**: Figures included within the text shall be referred to by
161+
their relative position. This is so the inclusion of a new figure, or the
162+
deletion of an old figure, does not force the re-numbering of all other figures
163+
and figure references.
164+
165+
* *The figure above shows the block chain*.
166+
* *~~Figure 1 shows the block chain~~*.
167+
168+
### Default Unit Of Value: Satoshis
169+
170+
Satoshis are the default unit of value.
171+
172+
* *I sent him satoshis.*
173+
* *~~I sent him bitcoins.~~*
174+
175+
## Punctuation
176+
177+
**Compound adjectives (hyphenation)**: Hyphenate them, unless the first part is
178+
an adverb (ending in "-ly", for example).
179+
180+
* *A UTXO used in multiple unconfirmed transactions is a likely sign of a double-spend attempt*.
181+
* *Double-spend risk decreases with each confirmation*.
182+
* *~~Successful miners receive a block reward of newly-created bitcoins~~*.
183+
184+
In these cases, "double-spend" is an adjective that modifies the word that
185+
follows it. However:
186+
187+
* *Criminals may attempt to double spend bitcoins to avoid payment*.
188+
* *The Bitcoin protocol provides a confidence score as a guide to protect against double spends*.
189+
190+
**Dashes**: Em dashes should be written as three hyphens---as in this
191+
example---without surrounding spaces. En dashes (which show ranges of
192+
values, such as 1--10) should be written as two hyphens with no
193+
surrounding spaces. Intra-word or connective hyphens should, of course,
194+
be written without any surrounding spaces.
195+
196+
**Periods**: One space after periods at the end of a sentence in pre-formatted
197+
text. (This does not apply in Markdown or HTML text files.)
198+
199+
* "Every major style guide---including the Modern Language Association
200+
Style Manual and the Chicago Manual of Style---prescribes a single
201+
space after a period." ---Farhad Manjoo, Slate,
202+
http://www.slate.com/articles/technology/technology/2011/01/space_invaders.html
203+
204+
### CamelCase Terms
205+
206+
Within regular text, treat camelCase terms as common nouns by using a lowercase
207+
first letter when not at the start of a sentence. If used in literal code, use
208+
uppercase `CamelCase` as appropriate.
209+
210+
We do not have a rule for when to use a camelCase term or when to break apart
211+
the camel case into separate words.
212+
213+
## Glossary
214+
215+
### Bitcoin
216+
217+
1. Not capitalized when referring to value or currency. (But satoshi
218+
should be used instead---see Default Unit Of Value section above.) Follow the same rules as for "dollar" and "yen".
219+
* *I spent 0.05 bitcoins at the restaurant*.
220+
* *I love the feeling of bitcoins in my pocket*.
221+
2. Capitalized when referring to something related to bitcoin that's *not* value. In these cases, treat it as if it's a proper name.
222+
* *I was 28 when I became involved in the Bitcoin community*.
223+
* *The Bitcoin white paper was a wake-up call*.
224+
* *The block chain provides Bitcoin's ledger*.
225+
3. Pluralized in normal fashion.
226+
* *I spent 0.05 bitcoins at the restaurant*.
227+
* *I have 3 bitcoins in my wallet*.
228+
* *You can buy my car for 4.5 bitcoins*.
229+
4. Refers only to a specific cryptocurrency. Never use it to refer to other cryptocurrencies, e.g. Litecoin, Dogecoin, etc..
230+
* *~~My favorite bitcoin is Primecoin~~*.
231+
232+
### Block chain
233+
234+
Two words. Ordinary capitalization.
235+
236+
* *The block chain provides bitcoin’s ledger*.
237+
* *His actions corrupted the block chain*.
238+
239+
### Bloom Filter
240+
241+
Although named after Burton Howard Bloom, bloom filter shall be treated as a common noun.
242+
243+
* *Filterload loads a bloom filter.*
244+
* *~~Filteradd adds a data element to a Bloom filter.~~*
245+
246+
### Change [output|transaction]
247+
248+
When referring to the part of a transaction input which is returned to the
249+
spender, “change”, try to use it with a clarifying modifier (as seen in the
250+
examples below) so the word doesn’t get confused with the regular English verb
251+
and noun words, change.
252+
253+
* *I spent the change transaction*.
254+
* *Always use a new public key for your change output*.
255+
* *You can resend change back to the same address*.
256+
257+
### Coinbase Transaction (Not Generation Transaction)
258+
259+
Use "coinbase transaction" instead of "generation transaction" to describe the first transaction in a block.
260+
261+
* *The coinbase transaction must claim the block subsidy and transaction fees.*
262+
* ~*Pool miners are often paid in generation transactions.*~
263+
264+
### Key pair
265+
266+
Two words. Ordinary capitalization.
267+
268+
* *A private key and a public are the two parts of a key pair*.
269+
270+
### Merkle Block
271+
272+
Two words when not the name of the `merkleblock` message.
273+
274+
### Merkle [Tree|Root|Leaf|Branch|Link]
275+
276+
Although named after Ralph Merkle, merkle tree elements are treated as common nouns.
277+
278+
* *A block header includes a merkle root.*
279+
280+
*References:* discussed on [pull #589](https://github.com/bitcoin-dot-org/bitcoin.org/pull/589#discussion-diff-18305822)
281+
282+
### Money
283+
284+
Avoid using “money” when referring to bitcoin. Use “bitcoin,” “millibit,”
285+
“satoshi,” or some other sub-bitcoin unit instead.
286+
287+
* *Bitcoin transactions send ~~money~~ satoshis*.
288+
289+
290+
### PaymentRequest, PaymentDetails, Payment, PaymentACK
291+
292+
Messages belonging to the payment protocol. Should always be capitalized and
293+
single words with camelCase as necessary. When not too distracting, they should
294+
be followed by the word "message", as in "PaymentRequest message". In
295+
particular, "Payment" should almost always be followed by "message" to
296+
disambiguate it from generic payments.
297+
298+
### Pubkey, Signature, And Redeem Scripts
299+
300+
The various script parts of transactions. Pubkey is capitalized as a
301+
regular common noun (i.e., the K is not capitalized)---exception, when
302+
used in an abbreviation (i.e. P2PKH means Pay-To-PubKey-Hash).
303+
304+
* *Outputs include a pubkey script.*
305+
* *Inputs include a signature script or a coinbase.*
306+
* *P2SH outputs pay a hashed redeem script.*
307+
308+
*References:* extensively discussed in pulls [#563](https://github.com/bitcoin-dot-org/bitcoin.org/pull/563) and [#566](https://github.com/bitcoin-dot-org/bitcoin.org/pull/566).
309+
310+
### Stale Block (Not Orphan Or Orphan Block)
311+
312+
Blocks which are not part of the most difficult (best) block chain shall be called stale blocks to avoid confusion with true orphan blocks that don't have a known parent block. Accordingly, forms of "orphan" shall not be used as a verb.
313+
314+
* *After the reorg, it became a stale block.*
315+
* ~*Because of propagation delays, miners produce one to two orphan blocks a week.*~
316+
* ~*The 0.8.0 blocks were orphaned by the 0.7.x chain.*~
317+
318+
*References:* discussed on [pull #589](https://github.com/bitcoin-dot-org/bitcoin.org/pull/589#discussion_r18310486).
319+
320+
### Standard Transaction & IsStandard()
321+
322+
A transaction which passes the Bitcoin Core IsStandard() test, indicating that
323+
it will be relayed or mined by default peers and miners. Mainly
324+
Pay-To-PubkeyHash (P2PH) and Pay-To-ScriptHash (P2SH) transaction types. Does
325+
not include genesis transactions. IsStandard() always begins with a capital I,
326+
and always includes the trailing parenthensis.
327+
328+
* *The first standard transaction appeared in block 170*.
329+
* *It passed the IsStandard() checks.*
330+
331+
### Timestamp
332+
333+
One word. Ordinary capitalization. Noun, but can be turned into a verb
334+
(timestamp, timestamped, timestamping...).
335+
336+
* *The timestamp showed that Gupta's transaction occurred before Smith's*.
337+
* *The block chain provides a timestamped record of all confirmed transactions*.
338+
339+
## Images
340+
341+
Information about creating or changing illustrations can be found in [the image README](https://github.com/bitcoin-dot-org/bitcoin.org/blob/master/img/dev/README).
342+
343+
SVG is the preferred file format for illustrations, but a corresponding
344+
PNG file with the same basename should be created. Bitmap images should
345+
be in PNG unless a special file format is warranted. All PNG images
346+
should be optimized by the command, `optipng -o7 <basename>.png`
347+
348+
(Note: optipng overwrites your original image, so make sure you have a
349+
backup before running it.)

0 commit comments

Comments
 (0)