Skip to content

Commit 0dc2a09

Browse files
committed
Fix build fail error
1 parent f345bb8 commit 0dc2a09

File tree

1 file changed

+57
-102
lines changed

1 file changed

+57
-102
lines changed

source/style-guide/code-example-guidelines.txt

Lines changed: 57 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -29,51 +29,35 @@ A code example is any size block of code set apart from regular text using a
2929
code-block directive. For details on valid directives, see the
3030
:ref:`code-block-reference` reference.
3131

32-
- Use code-block directives for all code examples. Code blocks are visually
33-
distinct, easier to read, and better interpreted by robot users (such as
32+
- Use code-block directives for all code examples. A code block is a visually
33+
and functionally distinct page element that defines and displays its content
34+
as code. It is easier to read and better interpreted by robot users (such as
3435
screen readers, AI models, and crawlers).
35-
- Do not use inline code markup to format code examples in ``monospace``. Use
36-
inline code for short references within text (such as method names).
36+
- Do not use inline code markup to write code examples. Use
37+
inline code to format code-related references within text in ``monospace``
38+
(such as method names).
3739

3840
1. Inline Code
3941
#. Code Block
4042

4143
.. figure:: /images/code-inline-vs-block.png
4244
:alt: Comparison of rendered inline code and a code block
4345

44-
Inline Code
45-
```````````
46-
47-
Inline code (sometimes referred to as "code in text") refers to code-related
48-
words or phrases, such as a method name in a sentence, rendered in
49-
``monospace``. To learn more about when to use ``monospace`` text, see
50-
`Text Formatting <https://www.mongodb.com/docs/meta/style-guide/style/text-formatting/#text-formatting>`__.
51-
52-
Inline code is not considered a type of code example.
53-
Inline code is not a code block, and it does not have the same formatting or functionality as a code block. Unlike code blocks elements, inline code isn't a different element. It is still paragraph text, similar to text formatted with **bold** or *italic* markup. To learn more, see `Inline Markup <https://www.mongodb.com/docs/meta/style-guide/markup/inline/#inline-markup>`__.
54-
55-
Code Block
56-
``````````
57-
58-
Code examples are always formatted in code blocks, which are distinct from the
59-
surrounding text. Code blocks support additional functionality, such as syntax
60-
highlighting or a caption label. For more information on the rST directives
61-
used to render a code block, see
62-
`Code Examples <https://www.mongodb.com/docs/meta/reference/code-blocks/>`__.
63-
6446
Types of Code Examples
6547
----------------------
6648

67-
.. NOTE related page: `Reference/Code Examples <https://www.mongodb.com/docs/meta/reference/code-blocks/`__
49+
.. note::
6850

69-
Although "code example" and "snippet" are often used interchangeably, this guidance uses "snippet" to mean a context-less block of code.
51+
Although "code example" and "snippet" are often used interchangeably, this
52+
guidance uses "snippet" to mean a context-less block of code.
7053

7154
We categorize code examples into the following types:
7255

7356
- :ref:`Usage Examples <code-category-usage-example>`: Standalone code blocks
7457
that show how to perform a task, including the relevant setup and context.
7558
- :ref:`Snippets <code-category-snippet>`: Code that illustrates a specific
76-
concept or detail in the context a larger example, tutorial, or reference page.
59+
concept or detail in the context of a larger example, tutorial, or reference
60+
page.
7761
- :ref:`Sample Applications <code-category-sample-app>`: Runnable applications
7862
demonstrating broader use cases.
7963

@@ -82,10 +66,11 @@ We categorize code examples into the following types:
8266
Usage Examples
8367
~~~~~~~~~~~~~~
8468

85-
Usage examples are complete, actionable code blocks that demonstrate how to
69+
Usage examples are self-contained, actionable code blocks that show how to
8670
accomplish a specific task using MongoDB tools, drivers, or APIs. Usage
87-
examples are self-contained--they include the context needed to understand,
88-
run, and adapt the code in the code block (e.g. variable declarations).
71+
examples include enough context to understand, run, and adapt the code
72+
contained in the code block (for example, the code includes any variable
73+
declarations).
8974

9075
.. code-block:: csharp
9176

@@ -99,49 +84,40 @@ run, and adapt the code in the code block (e.g. variable declarations).
9984
.. _code-category-snippet:
10085

10186
Snippets
102-
````````
87+
~~~~~~~~
10388

104-
Snippets are narrowly scoped code blocks that illustrate a specific concept or
105-
detail, typically as part of a broader explanation or tutorial. Unlike usage
106-
examples, they are informational, rather than actionable.
89+
Snippets are narrowly scoped code blocks that help explain a specific concept
90+
or detail. They are typically used as part of a broader explanation or
91+
tutorial, and are often meaningful only within that context.
10792

108-
Snippets are intended to support other content, and they rely on the
109-
surrounding text or context to be meaningful. In some cases, a snippet may
110-
contain intentionally incomplete or invalid code for demonstration purposes
111-
(for example, a snippet showing all possible argument options for a command).
93+
Snippets are intended to provide information. They aren't required to be valid
94+
or runnable code. In some cases, a snippets may contain intentionally
95+
incomplete or incorrect code for demonstration purposes (for example, a snippet
96+
showing all possible argument options for a command).
11297

11398
Snippets fall into one of the following subtypes:
11499

115100
- **Non-MongoDB command:**: a command-line (CLI) command for any non-MongoDB
116101
tooling (e.g. ``mkdir``, ``cd``, or ``npm``), often used in the context of a
117102
tutorial.
118103

119-
Snippets can fall into one of the following subcategories:
104+
.. code-block:: shell
120105

121-
- **Non-MongoDB command:** code blocks containing command-line commands for
122-
non-MongoDB tooling, typically in the context of a larger tutorial-style
123-
page. For example, terminal commands like ``mkdir``, ``cd``, ``npm``, etc.
106+
dotnet run MyCompany.RAG.csproj
124107

125-
.. code-block:: shell
126108
- **Syntax example**: an example of the syntax or structure for an API method,
127109
an Atlas CLI command, a ``mongosh`` command, or other MongoDB tooling.
128110

129-
dotnet run MyCompany.RAG.csproj
111+
.. code-block:: text
130112

131-
- **Syntax example:** a tightly-scoped code block showing syntax for an API
132-
method, an Atlas CLI command, a ``mongosh`` command, or other MongoDB tooling.
113+
mongodb+srv://<db_username>:<db_password>@<clusterName>.<hostname>.mongodb.net
133114

134-
.. code-block:: text
135115
- **Return example**: an example of an object, such as a JSON blob or sample
136116
document, returned after executing a corresponding piece of code. Commonly
137117
included as the output of an ``io-code-block``.
138118

139-
mongodb+srv://<db_username>:<db_password>@<clusterName>.<hostname>.mongodb.net
140-
141-
- **Return example**: a code block containing a JSON blob, example document, or
142-
other return object type. Use this snippet type to demonstrate what a user might expect from executing a piece of code.
119+
.. code-block:: text
143120

144-
.. code-block:: text
145121
A timeout occurred after 30000ms selecting a server using ...
146122
Client view of cluster state is
147123
{
@@ -157,38 +133,16 @@ Snippets can fall into one of the following subcategories:
157133
- **Configuration object example**: an example configuration object,
158134
often represented in YAML or JSON, enumerating parameters and their types.
159135

160-
A timeout occurred after 30000ms selecting a server using ...
161-
Client view of cluster state is
162-
{
163-
ClusterId : "1",
164-
Type : "Unknown",
165-
State : "Disconnected",
166-
Servers :
167-
[{
168-
ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }",
169-
EndPoint: "Unspecified/localhost:27017",
170-
ReasonChanged: "Heartbeat",
171-
State: "Disconnected",
172-
ServerVersion: ,
173-
TopologyVersion: ,
174-
Type: "Unknown",
175-
HeartbeatException: "<exception details>"
176-
}]
177-
178-
179-
- **Configuration object example**: a code block showing an example object,
180-
often represented in YAML or JSON, enumerating parameters and their types.
136+
.. code-block:: ini
181137

182-
.. code-block:: ini
183-
184-
apiVersion: atlas.mongodb.com/v1
185-
kind: AtlasDeployment
186-
metadata:
187-
name: my-atlas-cluster
188-
spec:
189-
backupRef:
190-
name: atlas-default-backupschedule
191-
namespace: mongodb-atlas-system
138+
apiVersion: atlas.mongodb.com/v1
139+
kind: AtlasDeployment
140+
metadata:
141+
name: my-atlas-cluster
142+
spec:
143+
backupRef:
144+
name: atlas-default-backupschedule
145+
namespace: mongodb-atlas-system
192146

193147
.. _code-category-sample-app:
194148

@@ -212,16 +166,17 @@ Keep the following in mind as you write code examples:
212166
- Treat code like writing: Keep it simple, readable, and relevant to the task.
213167
- Write code that is easy to understand, even if it isn't the most efficient or
214168
clever.
215-
- Introduce each code block with context.
216-
- List or note any prerequisites or code dependencies, especially in a tutorial.
169+
- Introduce each code block with context, as you would a list or table.
170+
- Include any prerequisites or code dependencies needed for a piece of code.
217171
- Use descriptive names that clearly convey the purpose of the code element
218172
(e.g. variable, function, class) or placeholder.
219173
- If a code is not intended to be directly used or adapted, such as a return
220174
object example snippet, make sure the code block is not copyable. To learn
221175
how to set the copyable option, see :ref:`code-block-reference`.
222-
- Don't write code examples for anti-patterns. If readers should be aware of an
223-
anti-pattern or a commonly made mistake, communicate this clearly in the
224-
surrounding text, an admonition, or an inline code comment.
176+
- Don't write code examples for anti-patterns. If you need to note an
177+
anti-pattern or a commonly made mistake, use the
178+
surrounding text, an admonition, or an inline code comment, and ensure that
179+
it cannot be mistaken for a recommended pattern.
225180
- If a code example is not production worthy in a significant way, communicate
226181
this to readers through inline code comments *and* in the surrounding text.
227182
- Never use real customer data or hard code secrets in your code. If you're
@@ -237,32 +192,32 @@ Keep the following in mind as you write code examples:
237192
- If you have to make changes or take additional steps to get an example to
238193
work, make sure those details are reflected in the doc.
239194

240-
Considerations for Robot Users, LLMs, and Other AI Models
241-
--------------------
242-
243195
.. note::
244196

245-
For any questions or help writing or testing code examples, reach
197+
For any questions or for help writing or testing code examples, reach
246198
out to the ``@DevDocs`` team or use the ``#ask-devdocs`` Slack channel.
247199

248200
Considerations for LLMs
249201
-----------------------
250202

251-
The robot users (such as LLMs and other AI models) that consume our docs are unable to infer meaning or intent from context.
203+
Unlike human readers, the robots that consume our docs (such as LLMs and other
204+
AI models) can't infer meaning or intent from context. Robot users struggle
205+
with ambiguity, unclear boundaries, partial or implicit information, and
206+
non-standard patterns.
252207

253208
To ensure that our code examples are robot friendly, keep the following in mind:
254209

255-
- Write code examples that are self-contained and provide enough information
256-
for robot users to understand their purpose without relying on surrounding
257-
text or context.
258-
- Don't split code into multiple pieces.
259-
- Use inline comments to clearly mark any omitted or truncated sections.
260-
- Explain intent, purpose, or expected code behavior through surrounding text *and* inline comments.
261-
- File names, file structure, and code follows idiomatic, canonical patterns
210+
- Prefer atomic code examples: code should be as self-contained and self-descriptive as possible so that robot users can understand the code more easily.
211+
- Explain intent, purpose, or expected code behavior through surrounding text
212+
*and* inline comments.
213+
- Don't interrupt a single code block with text explanations. Keep explanatory
214+
text before or after the code block, and use inline comments for explanations
215+
within the code block.
216+
- Prefer conventional file structure, names, and canonical patterns
262217
(e.g. ``main()``, ``index.js``, ``connect()``). Avoid unnecessary aliasing or
263218
non-standard structures unless explained clearly.
264219
- Use consistent, descriptive names that indicate purpose. Avoid vague names
265220
like ``foo``, ``x``, or ``doStuff()``.
266221
- Make sure the correct language is specified for every code block.
267-
- Clearly mark placeholders and explain how to replace them through an inline
268-
comment.
222+
- Clearly mark and explain any placeholders, omissions, or truncated code
223+
through inline comments.

0 commit comments

Comments
 (0)