Skip to content

Commit 9688315

Browse files
committed
write up styleguide
1 parent 229ad51 commit 9688315

File tree

2 files changed

+263
-0
lines changed

2 files changed

+263
-0
lines changed

.spelling

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ V1
138138
localhost:8080
139139
UI
140140
http
141+
metasyntactic
142+
callout
143+
callouts

STYLEGUIDE.md

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
# Style Guide
2+
3+
Our aim is to teach developers how to build great Web Components. An important part of that is writing great
4+
documentation, that's not only correct but easy to ingest. Good prose allows people to learn quickly and easily.
5+
6+
## Audience
7+
8+
Write content for people who:
9+
10+
- Are developers. Do not shy away from general developer terms like "linting" or "array".
11+
12+
- Already know some JavaScript, but maybe are not familiar with some of the newer features (especially class related
13+
features, many of which are new). Assume the reader is comfortable writing ES6 code. Any language features newer than
14+
ES6 should be accompanied by links or explanations.
15+
16+
- May or may not have used front-end libraries and frameworks before. While it might be safe to assume they have, it's
17+
safer to avoid analogies to other frameworks. Assume the reader is comfortable with HTML.
18+
19+
- Comfortable reading and seeing code. If you're introducing a concept and it becomes difficult to explain without
20+
multiple paragraphs, consider using a code example to explain an idea. Just make sure not to introduce a lot of new
21+
code at once. Each code blocks should only introduce one or two new concepts related to the section.
22+
23+
- Are not front-end experts, but need or want to learn this technology to complete a task or improve their
24+
understanding. Avoid assuming knowledge about front end concepts like the Events, or UI paradigms.
25+
26+
- Are not accessibility experts. Accessibility is very important to cover, but do not assume the reader is confident
27+
with using assistive tools, or has a robust understanding of assistive technologies.
28+
29+
While we want to reach an audience that is perhaps new to development, we want to avoid our content leaning toward
30+
introducing readers to JavaScript & HTML in general. Keep focused on Web Components and related technologies. If you're
31+
covering language features, explain them within the context of Web Components, rather than a general explanation of how
32+
the feature works.
33+
34+
### Language & Locale
35+
36+
Write content in US English, but with a view to readers who may not speak English as their first language. Avoid overuse
37+
of English cultural references. Avoid long words.
38+
39+
Make use of the `npm run check` command which can lint for issues around readability & spelling.
40+
41+
## Medium
42+
43+
Write content knowing that people are reading this on the web. Read [the Nielsen Norman article on How Users Read on the
44+
Web][how-users-read-web]. Some important takeaways:
45+
46+
- Many people scan a page. Make sure a page is easy to scan. Headings and bullet points are helpful here.
47+
48+
- Web users are busy. Stick to facts. Avoid overly verbose sentences.
49+
50+
- Avoid "marketese". Avoid making bold claims about a feature. Again, stick to facts.
51+
52+
- Break a page into meaningful subheadings. This helps readers find content useful for them.
53+
54+
- Introduce one idea per paragraph, and try to introduce it in the first few words. This allows readers to skip ideas
55+
they know.
56+
57+
The web is interactive - we should embrace that and leverage it. Interactive demos are often better learning tools than
58+
lots of words. Colorful diagrams, animations, interactive forms are all welcome. Avoid "flashy" animations though. Any
59+
interactive demos, diagrams or animations should move the reader toward learning.
60+
61+
## Voice
62+
63+
All writing has a voice. Ours should be concise, somewhat casual and friendly, but factual:
64+
65+
- Write in the [active voice][active-voice]. Describe things as if they are happening, rather than have happened.
66+
67+
- Value the readers time. Be incisive. Each sentence should produce value in moving the reader toward learning. Keep
68+
sentences under 20 words. Try to keep paragraphs under 5 sentences. An individual page should take less than 10
69+
minutes to read (that's roughly 200 lines of markdown). Break up longer pages into multiple sections.
70+
71+
- Content should be serious, but does not need to be stuffy or pompous. Write as if you're explaining a concept as a
72+
mentor, or speaking at a conference, not as if you're lecturing in front of a podium.
73+
74+
- Write in a casual tone, but avoid overly conversational phrases. Feel free to use contractions like "it's" or
75+
"you're", but try to avoid being too casual. Avoid phrases like "check this out".
76+
77+
- Each section should ideally stand by itself. It won't need introductions or transitions between sections or pages.
78+
Avoid trying to encourage the reader to read on. Don't greet the reader with "hello" or "welcome" or "in this section
79+
we'll...". If a sentence starts with "Let's" then it's a good sign it should be reworded or removed.
80+
81+
- Try to write without strong emotions, as it can reduce the confidence the reader has in us - the author. Suggesting
82+
things will be "fun" or "painful" can make text sound like marketing. Don't make use of exclamation points, as they
83+
imply a statement is surprising.
84+
85+
- Avoid caveats or hedging statements, they reduce confidence. Avoid words like "generally", "sometimes". Don't use
86+
phrases like "you might be able to" or "it can be".
87+
88+
- Outside of the Blog, avoid speaking personally. Avoid referring to "we" or "I". Similarly steer away from overuse of
89+
the word "you", especially if it can come across presumptive. E.g. "you might not know" or "you've already...".
90+
91+
## Structure
92+
93+
Each page should cover a discrete topic - but topics can span multiple pages when they get complex.
94+
95+
### Introductory paragraphs
96+
97+
Following the [inverted pyramid][inverted-pyramid], write most important need-to-know content in the first few
98+
paragraphs, directly under the main headline of the page. Try to impart a conclusion within the first few paragraphs,
99+
and use the rest of the page to expand on the details or nuance of that conclusion.
100+
101+
Imagine the reader can only read the first paragraph. What information would they take away? Could they reach a
102+
conclusion that would be the same if they read the whole page?
103+
104+
The first paragraph may introduce a new concept. Try to introduce it with a motivation; why is it important for Web
105+
Components? Avoid "filler" intros which are there to lead a reader to the rest of the page.
106+
107+
#### A good introductory paragraph
108+
109+
> Web Components can be defined either a _Autonomous Custom Elements_ or as _Customized Built-in Elements_. The most
110+
> popular way to make elements is to use the Autonomous Custom Element style, by making up your own tag and extending
111+
> HTMLElement. Each style comes with different trade-offs.
112+
113+
- This introduces the core concepts the page will expand upon; the two types of Web Component. These are also introduced
114+
in the first sentence.
115+
- It gives the reader a quick conclusion up front; "the most popular way to make elements is". The reader could stop
116+
reading here, and still have learned something.
117+
- It avoids unnecessary sentences, it does not have preamble.
118+
- Each sentence is one fact.
119+
120+
#### Bad introductory paragraphs
121+
122+
> In this section we'll talk about the different types of Web Components you can define. One way is with _Autonomous
123+
> Custom Elements_. Another is _Customized Built-in Elements_. It's up to you which one to chose, each has different
124+
> trade-offs.
125+
126+
- The first sentence is an unnecessary introduction. It does not add any new information - as the reader can infer what
127+
the page is about from the title.
128+
- Two sentences are devoted to defining the two types of components, but they rely on each other for context. Take each
129+
sentence out of the paragraph and it doesn't have any meaning.
130+
- The reader is not left with any decisive information, instead now have a choice and no information on how to make that
131+
decision.
132+
133+
> Web Components can either be an _Autonomous Custom Element_ or a _Customized Built-in Element_. Picking one or the
134+
> other will have trade-offs around CSS & Styling, ShadowDOM, Nesting & Semantics, Behavior & API, Accessibility, and
135+
> more. Read on for more detail...
136+
137+
- While the first sentence leads right in to the topic, the second sentence overwhelms the reader in trying to summarize
138+
all the talking points in the page.
139+
- The reader still has no take-away conclusion of which style to chose.
140+
- Readers will likely get a sense that this decision is complex and maybe a wrong choice is dangerous.
141+
- The last sentence is unnecessary; it's implied that the rest of the page will offer more detail. Our aim is to get the
142+
reader to a conclusion quickly, not to entice them to read an article.
143+
144+
### Headings
145+
146+
Headings should be used to break up the page into individual talking points. Not only does this anchor a reader to what
147+
a section is for, but it's also really useful for linking readers to specific content.
148+
149+
- Each page has an `H1`, so headings within a page should start at `H2` (`##`). If a topic needs breaking down much
150+
beyond `H3` (`###`) that could be a sign that it needs to be across multiple pages.
151+
152+
- Headers should be unique within a page, as this means each one can be linked to.
153+
154+
- Don't rely too heavily on the context of a higher level heading, but avoid repetition among headers. Avoid generic
155+
headings like "Introduction" or "More detail".
156+
157+
- Avoid more than 5 consecutive paragraphs between headings. This is an indicator that multiple concepts are being
158+
discussed. Break it down.
159+
160+
- Avoid more than one block of code per heading; if you need more than one code example to explain a concept then
161+
consider breaking down the concept, or refactoring the code.
162+
163+
- Headings should not end in punctuation. Question in headings are best avoided - headings should be answers. Similarly,
164+
avoid titles starting "How to" or "Here's how".
165+
166+
- Avoid code blocks in headings. These are tricky to read and can result in the links being messy.
167+
168+
Some examples of good and bad headings:
169+
170+
- ❌ How to declare a template
171+
- ✓ Declare a template in HTML
172+
173+
- ❌ Naming elements
174+
- ✓ Make element names concise, but clear
175+
176+
- ❌ What methods are available on EventTarget?
177+
- ✓ Available methods on EventTarget
178+
179+
- ❌ See also
180+
- ✓ Further reading on Web Browsers
181+
182+
### Code
183+
184+
Code examples are a very useful tool to explain concepts, but they should be treated with care.
185+
186+
- Make sure each code example has a paragraph explaining what the code does or how it behaves. Code examples should not
187+
be in place of prose, they should reinforce the prose. Think of them like figures.
188+
189+
- Make sure all code examples run! Good code examples can be copied and pasted into the browsers devtools and produce an
190+
output that helps the reader understand the concept.
191+
192+
- Use comments, `console.log`, or `console.assert` to explain code, but use them sparingly. Keep comments short, only
193+
explaining the very next block of code. If a comment is more than a couple of lines then move it outside into a
194+
paragraph. Code comments or `console` statements are useful for highlighting the specific concept a section is talking
195+
about.
196+
197+
- Keep code samples less than 50 lines of code. Break up pages with more than 200 lines of code, or otherwise reduce the
198+
code within them.
199+
200+
- Make sure code examples are well motivated. Avoid overly contrived code, including [metasyntactic
201+
variables][metasyntactic-variables]. Write code that you'd feel comfortable introducing into a code base.
202+
203+
### Call outs
204+
205+
Keeping focused on a topic is important, but it can result in losing useful but tangential points. Using callouts (or
206+
asides) is a great way to keep this content, and make it more useful.
207+
208+
Consider using callouts sparingly. Excessive use of callouts as they can be noisy. Keep them to under 5 per page. Keep
209+
callouts to one paragraph long. Do not add code examples to a callout. If you can use an image, animation, or
210+
interactive demo instead of a callout, do that instead.
211+
212+
To use a callout, put a paragraph between `{% tip "type" %}` and `{% endtip %}`. Three main types of callouts are used
213+
on the site:
214+
215+
- Informational (`"info"`): This can be used to add additional context that would otherwise deviate from the main
216+
talking point. Useful for describing for tips and tricks, asides, etymology or definition of terms.
217+
218+
- Warning (`"warn"`): This can be used to describe pitfalls or constraints around an API. Useful for describing gotchas,
219+
that wouldn't result in an error but might be surprising for a reader.
220+
221+
- Danger (`"danger"`): This can be used to describe error scenarios or things that won't work. Useful for describing
222+
when an API throws a validation error.
223+
224+
### Concepts vs APIs
225+
226+
Concepts should either be proper nouns like Web Components, acronyms like HTML, or phrases like _private state_.
227+
Italicize phrases to highlight that they are concepts to the reader. Always use title case for proper nouns (so never
228+
"web components", always "Web Components"). Italicizing concepts also helps to highlight when a paragraph is talking
229+
about too many concepts at one time. Concepts should be consistently named across the page.
230+
231+
APIs are concrete versions of concepts. For example Shadow DOM is a concept, `ShadowRoot` is a concrete class. Always
232+
quote APIs in back ticks. Take care to avoid mixing concepts and APIs especially when they are closely related -
233+
`ShadowRoot` is synonymous with _Shadow DOM_.
234+
235+
APIs should be treated like verbs, for example refer to code acting on a `ShadowRoot`, while concepts should be treated
236+
like nouns. Don't prepend articles to concepts, for example it's "Shadow DOM" not "the Shadow DOM".
237+
238+
Take care with acronyms. Only use acronyms when you have high confidence the target audience will already know the
239+
acronym. HTML, DOM, API - these are all acceptable acronyms for the target audience. Avoid making acronyms of new
240+
concepts, for example always use Declarative Shadow DOM. As a general rule, if you need to explain an acronym within
241+
your prose, then don't use it.
242+
243+
Concepts are useful for capturing a group of APIs, or a technique. For example a Declarative ShadowDOM refers to a
244+
`template` with a `shadowroot=` _attribute_ inside of HTML. A concept needs to be set up before its use on a page, but
245+
once it has been explained, you can continue to refer to it without having to recover the APIs it's comprised of.
246+
247+
## Ending notes, summaries
248+
249+
Pages can end abruptly when a section has ended. They do not need to summarize or conclude the topic.
250+
251+
Do not try to write prose transitioning to the next page, as not only is this unnecessary but it can also make moving
252+
pages around more difficult.
253+
254+
Summaries can be useful for reinforcing complex information throughout the document, but use them sparingly. A summary
255+
should stand a lone as useful content, and not attempt to clarify unclear content.
256+
257+
[how-users-read-web]: https://www.nngroup.com/articles/how-users-read-on-the-web/
258+
[active-voice]: https://en.wikipedia.org/wiki/Active_voice
259+
[inverted-pyramid]: https://www.nngroup.com/articles/inverted-pyramid/
260+
[metasyntactic-variables]: https://en.wikipedia.org/wiki/Metasyntactic_variable

0 commit comments

Comments
 (0)