In previous posts, I explored how structural principles and writing quality standards that serve human readers also serve AI tools. Those posts focused on the prose found in all technical documentation. API documentation presents an additional challenge: teaching concepts through code examples.
I asked Claude what makes code examples easy for an AI tool to process. The patterns it identified align with established principles from instructional design and technical communication pedagogy. Once again, the fundamentals endure—whether you’re teaching human developers or enabling AI tools to extract meaning from documentation.
Code presentation patterns that help processing
Claude identified the following helpful patterns for presenting code in documentation.
I’ve added comments in italics to Claude’s conversation for additional context and clarification.
Syntax highlighting with language specified
```javascript
// Language tag makes intent clear
const result = await fetchData();
```
versus unmarked blocks requiring inference
Complete, runnable examples
- Includes necessary imports and dependencies
- Shows actual input and expected output
- Avoids fragments with ellipses everywhere
I discuss the nuance of this later in the article.
Inline comments explaining non-obvious logic
```python
# Convert UTC to user's local timezone before display
local_time = utc_time.astimezone(user_tz)
```
Variable names that indicate type and purpose
- userConfig vs data
- isAuthenticated vs flag
- errorMessage vs msg
