원클릭으로
code-example-best-practices
Guidelines for writing effective code examples in technical blog posts
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Guidelines for writing effective code examples in technical blog posts
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Strategic search planning for agent-driven research. Generates structured search-term matrices with tiered fallback strategies, engine-specific operators, and grading criteria before executing any searches. Use this skill whenever research requires more than a single search query — comparing technologies, verifying claims across sources, surveying a landscape, investigating a multi-faceted question, or building evidence for a decision. Do NOT use for quick factual lookups, fetching a single known URL, or questions answerable from a single source. Covers tech, academic, regulatory, and general domains. Think of it as "research planning" — the matrix is the plan, execution comes after.
Create language conversion skills for translating code from language A to language B. Use when building 'convert-X-Y' skills, designing type mappings between languages, establishing idiom translation patterns, or defining conversion methodologies. Provides foundational patterns that specific conversion skills extend.
Guide for translating code between programming languages. Use when converting code from one language to another, planning language migrations, understanding conversion challenges, asking about type mappings, idiom translations, or referencing pattern mappings. Covers APTV workflow, type systems, error handling, concurrency, and language-specific gotchas.
Identify skill coverage gaps and improvement opportunities. Use when analyzing missing skills for a task, creating skill gap issues, evaluating skill effectiveness, or refining skill progressive disclosure.
Validate Claude Code skills against best practices. Use when checking skill quality, running validation, or creating improvement issues.
{{DESCRIPTION}}
| name | code-example-best-practices |
| description | Guidelines for writing effective code examples in technical blog posts |
| created | "2025-02-19T00:00:00.000Z" |
| updated | "2025-02-19T00:00:00.000Z" |
| tags | ["blog","code","examples","documentation"] |
| source | blog-workflow-plugin |
Guidelines for writing clear, effective code examples in technical blog posts.
Code examples are often the most valuable part of technical content. This skill provides standards for writing code snippets that are easy to understand, copy, and adapt.
This skill covers:
This skill does NOT cover:
| Element | Guideline |
|---|---|
| Language tag | Always specify (python, bash, etc.) |
| Length | Under 30 lines preferred |
| Width | Under 80 characters per line |
| Comments | Explain "why", not "what" |
| Imports | Include when relevant to example |
Code that doesn't run frustrates readers. Every example should:
Good:
import os
from pathlib import Path
# Read config from environment (provide default for local dev)
api_key = os.environ.get("API_KEY", "your-api-key-here")
config_path = Path("config.json")
if config_path.exists():
config = json.loads(config_path.read_text())
Bad:
# Missing imports, undefined variables
config = json.loads(config_path.read_text())
Show only what's necessary. Strip everything else.
Good:
# Retry with exponential backoff
for attempt in range(max_retries):
try:
return make_request(url)
except RequestError:
sleep(2 ** attempt)
raise MaxRetriesExceeded()
Bad:
# Too much context obscures the pattern
import requests
import logging
from typing import Optional
from dataclasses import dataclass
logger = logging.getLogger(__name__)
@dataclass
class Config:
max_retries: int = 3
base_url: str = "https://api.example.com"
timeout: int = 30
def make_request(url: str, config: Optional[Config] = None) -> dict:
config = config or Config()
# ... 20 more lines before getting to the retry logic
For complex examples, build up incrementally:
def process_data(data):
return [item.upper() for item in data]
def process_data(data):
results = []
for item in data:
try:
results.append(item.upper())
except AttributeError:
results.append(str(item).upper())
return results
def process_data(data, logger=None):
results = []
for item in data:
try:
results.append(item.upper())
except AttributeError:
if logger:
logger.warning(f"Converting {type(item)} to string")
results.append(str(item).upper())
return results
Help readers verify they're on track:
$ curl -s https://api.example.com/health | jq
{
"status": "healthy",
"version": "1.2.3"
}
>>> calculate_hash("hello world")
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
Always specify the language for syntax highlighting:
```python
def example():
pass
```
Common tags: python, javascript, typescript, bash, json, yaml, sql, go, rust
Keep lines under 80 characters to prevent horizontal scrolling:
# Good: Line breaks at logical points
result = (
some_long_function_name(
parameter_one=value,
parameter_two=other_value,
)
)
# Avoid: Long lines that scroll
result = some_long_function_name(parameter_one=value, parameter_two=other_value, parameter_three=another_value)
Comment the "why", not the "what":
# Good: Explains reasoning
# Use a set for O(1) lookup on large datasets
seen = set()
# Bad: States the obvious
# Create a set called seen
seen = set()
Inline comments for non-obvious lines:
response = client.get(url, timeout=30) # Server can be slow during peak hours
data = response.json().get("results", []) # API returns empty list as null
Use obvious placeholders that won't accidentally work:
| Type | Good Placeholder | Bad Placeholder |
|---|---|---|
| API keys | your-api-key-here | abc123 |
| URLs | https://api.example.com | https://api.com |
| Passwords | <your-password> | password123 |
| Emails | user@example.com | test@test.com |
| IDs | 12345 or <user-id> | 1 |
Show what changed when modifying code:
def process_data(data):
- return data.upper()
+ return data.strip().upper()
Or use comments to highlight changes:
def process_data(data):
return data.strip().upper() # Added strip() to handle whitespace
Show both environment variables and code:
# Set in your shell or .env file
export DATABASE_URL="postgres://user:pass@localhost:5432/mydb"
export REDIS_URL="redis://localhost:6379"
import os
DATABASE_URL = os.environ["DATABASE_URL"]
REDIS_URL = os.environ.get("REDIS_URL", "redis://localhost:6379")
Use $ prefix for commands, show output without prefix:
$ npm install express
added 57 packages in 2.3s
$ npm start
Server running on http://localhost:3000
When showing multiple files, use clear headers:
src/config.py
DATABASE_URL = "postgres://localhost/mydb"
src/main.py
from config import DATABASE_URL
When showing errors, include enough context to diagnose:
>>> import missing_module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'missing_module'
Never use images for code. Always use text that readers can copy.
Run every example before publishing. Typos and API changes break tutorials.
Don't assume readers know the file structure or have run previous steps:
# Bad: Where does 'client' come from?
response = client.get("/users")
# Good: Show the setup
from myapp import create_client
client = create_client(api_key=os.environ["API_KEY"])
response = client.get("/users")
Never include real credentials, even in "example" form:
# NEVER do this
api_key = "sk-live-abc123..." # This looks like a real key
# Do this instead
api_key = os.environ["API_KEY"]
technical-writing-style skill - Writing prose around codecontent-structure-patterns skill - Where code fits in post structure