惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Schneier on Security
Cisco Talos Blog
Cisco Talos Blog
T
ThreatConnect
J
Java Code Geeks
博客园 - 司徒正美
A
Arctic Wolf
T
True Tiger Recordings
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
V
Vulnerabilities – Threatpost
Recorded Future
Recorded Future
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
The Register - Security
The Register - Security
S
Securelist
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
I
Intezer
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
K
Kaspersky official blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
V
V2EX
小众软件
小众软件
F
Fox-IT International blog
Martin Fowler
Martin Fowler
Apple Machine Learning Research
Apple Machine Learning Research
T
Tenable Blog
F
Future of Privacy Forum
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
T
Threatpost
I
InfoQ
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Tor Project blog
G
GRAHAM CLULEY
D
DataBreaches.Net

DEV Community

The N+1 Query That Killed Our Database, And How I Fixed It Training Data Provenance: The Manifest Diff That Explains the Hash Add SVGIcons MCP to Claude Code and Find SVG Icons from Your Terminal 3 CLI Tools You Can Buy with Crypto — No KYC, No Subscriptions COSS Weekly: OpenClaw competitor NanoClaw Raises $12M, Dust Raises $40M, Sonar Acquires Gitar, and more How to know if you actually need mobile proxies (without buying any) Building Cursor for Community: A Buildathon Built on Time Pressure How we built a PII masking layer for LLM APIs — local detection, reversible tokens, one line to integrate Why MLFQ Was Way Ahead of Its Time Add Runtime Limits to Claude Agent Workflows I Built a Prompt Injection Detector with 98% Recall on Unseen Attacks. Here's Why Data Beat Architecture. 8 Vite Config Options Every Developer Should Know (Vite 8) Feature Flags That Forgot to Leave Why Trust Infrastructure Is Becoming the Hidden Layer of Donation Platforms XyPriss: Rethinking Core Performance and Zero-Trust Architecture in Modern Backends Designing Configuration for Scalable Treasure Hunts SSH Login Delays: The 10-Second Wait That Drives Us Crazy Building Production Multi-Agent Workflows in n8n: What 50 Deployments Taught Us A 3-layer memory system that gives Claude Code persistent context across sessions. Trishul SNMP Suite 2.0.1: Better MIBs, Traps, and SNMP Labs How I built a production AI SaaS as a solo developer Auto-labelling 1.2M robotics frames with VLMs: a failover story India’s Laws Were Not Built for AI — And Courts Are Filling the Gap skill-insp: A Skill That Scores Other Skills Clprolf Minimalist Messaging in the Age of AI What's actually in a good .cursorrules file? I built 10 of them — here's what I learned Building Strong Python Basics – Loops, Functions and Logic How to Choose the Right Tech Stack for Your Project I built a free multi-tab JSON editor — here's what I learned HTTP Headers Every Developer Should Know (2026) Building Cross-Platform Digital Products: Challenges and Best Practices Data Privacy in the Age of AI: How Product Teams Can Build Trust with Users What Would WordPress Look Like If It Were Designed Today? Why Backup Success Does Not Mean Database Recoverability Local AI Office Assistant That Never Sends Your Documents to the Cloud Building TaskForge: Translating Enterprise Chaos into an Open-Source Scheduler Tesla P40 in a Homelab: 24GB of Inference on a Budget Llama 4: Meta's Latest — Scout, Maverick, and the MoE Revolution George Hotz called AI code 'slop.' He's half right. Como Construir um Fluxo de Trabalho Baseado em Engenharia de Prompt e Automação We Audited Our Agent Tool-Call Traces. Half Our Eval Data Was Garbage. The Hidden Cost of Downtime: How SRE Error Budgets Protect National Economic Infrastructure Getting started with openHUMANS can be an exciting venture for developers looking to create innovative applications in the realm of human-ce Stack Overflow: A Powerful Community for Developers and Learners From Language Models to Humanoid Minds ✨ Road to Senior #2: How Computers Think in Numbers Why LLM debugging fails on fragmented repository context How to Deploy a LangGraph Agent on AWS Bedrock AgentCore An outreach kit for solo founders whose drafts can't hallucinate Open Satchel is live Amy Kwalwasser and the Growing Importance of Quantum Risk Modeling I Built ShellReq - A Native API Client for VS Code & Terminal If Microsoft and Uber can't afford AI coding, what chance do the rest of us have? MADCAP: Building a Multi-Agent Debate CLI That Argues With Itself So You Don't Have To Why most AI fails at IDOR (and how AMAS fixes it with causal reasoning) How to Audit a Laravel Codebase You've Inherited LangGraph 워크플로우 템플릿 (v34) BugBench: a developer origin story and practical guide for VS Code / Kiro users A solution to messy token systems for Next.js A NestJS reference app that proves the nest-native stack under realistic backend pressure Observability for AI Systems: Monitoring Drift, Hallucinations, and Reliability in Production I Thought “Data Analyst” Was the Whole Game… Then I Entered the Data Avengers Office 👀 Create and configure network security groups How to analyze the cost of Kafka? How I Shipped 2,500+ Commits With AI Agents Using a 12-Phase Workflow [Boost] We built MDCMS, a Markdown-first CMS for teams using AI agents Zero Heap Allocations at 1.18 GB/s: Deep Dive into ForgeZero 4.0.x The Minimum Viable Test Suite for Working with Agents Why Perplexity Started Citing My Blog: 5 Changes That Actually Worked Sync Supabase via OAuth: No Connection String Needed I asked three AI models the same API question. Only one had it right. Implementing Saga Pattern With Lambda Durable Function Why does AI forget what you said (and how to fix it) I built a daily Wordle-style game for AI tools - Here's how Mapping Polish company structures: querying KRS direct via API Built tmpdrop — a tiny self-hosted ephemeral file drop Running Local LLM - 0$ Personal Agentic AI Assistant - Part 3 LLD Object-Oriented Design: Interfaces & Abstract Classes (Designing Contracts) The Smaller Ship: Vitalik, the Ethereum Foundation's Restructuring, and What It Leaves for Investors Looking for 4 people to build something weird with me Building a Local-Only RAG System with Ollama and TypeScript The False Positive Tax: a 1:1 TP:FP analysis of eslint-plugin-security What's new in Data Preprocessor 1.5.x — R codegen, Robust Scaler, and a deadlock post-mortem How I self-hosted my Flask app on an old laptop for almost free I built a free DSA interview prep site because I was tired of the existing options I built an AI agent that migrates Next.js Pages Router to App Router Prisma Query Logging and PostgreSQL: Where the ORM Ends and the Database Begins Prisma query logging y PostgreSQL: dónde termina el ORM y empieza la base From Browser to Server : The Journey of an HTTP Request (Demystifying the Web’s Infrastructure) Santa Augmentcode Intent Ep.6 I Benchmarked 17 ESLint Security Plugins. Only One Found Every Vulnerability. How to Build a High-Performance Image Optimization Pipeline in 5 Minutes 50 Linux Commands Every DevOps Engineer Must Know Less Toil, More Flow - Automating the Path from Request to Implementation The Code Review Checklist I Actually Use How I run a small blog on Astro 5 + Content Collections Git: Best Practices for Professionals How IBM Bob Became My Everyday Coding Companion
Docstrings vs Markdown Docs: What Should Developers Actually Write?
Anoop Kumar · 2026-05-26 · via DEV Community

Every developer hits this wall eventually. You know you should document your code. You've heard the lectures. But then you're staring at your project and wondering... do I write docstrings? A README? Both? Some massive documentation site?
It's genuinely confusing. And nobody explains it well.
Here's the thing. Docstrings and markdown documentation aren't competing approaches. They do different jobs. Docstrings live inside your code and document how your API works. Markdown files sit outside your code and explain how to actually use your project.
Different purposes. Different audiences. Both necessary for anything serious.

What Are Docstrings?

Docstrings are inline documentation written directly in your source code. Triple quotes in Python. Special comment blocks in other languages.

`def calculate_total(items, tax_rate=0.08):
    """Calculate the total price including tax.

    Args:
        items: List of item prices.
        tax_rate: Tax rate as decimal. Defaults to 0.08.

    Returns:
        Total price with tax applied.
    """
    subtotal = sum(items)
    return subtotal * (1 + tax_rate)`

Enter fullscreen mode Exit fullscreen mode

That's a docstring. Lives right there with the function. Describes what the function does, what it takes, what it returns.
The purpose is API reference documentation. When someone imports your library and calls help(calculate_total), they see that docstring. When documentation tools scan your codebase, they pull these docstrings out and build API docs from them.
Python has several formatting conventions. Google style is clean and readable. NumPy style works well for scientific code with complex parameters. Pick one and stick with it.
JavaScript uses JSDoc with a different syntax but same idea. Java has Javadoc. The concept translates across languages.

What Is Markdown Documentation?

Markdown documentation means external files. Your README.md. Tutorial guides. Architecture docs. Anything written in those .md files that live alongside your code but not inside it.

# Getting Started

Install the package:

pip install mypackage

Quick example:

from mypackage import calculate_total
total = calculate_total([10.99, 24.50, 8.75])

Enter fullscreen mode Exit fullscreen mode

This is project-level documentation. It explains the big picture. How to install. How to get started. Why your project exists. What problems it solves.
Tools like MkDocs turn these markdown files into documentation websites. Docusaurus does the same thing. GitHub renders your README automatically on your repo page.
Different beast from docstrings entirely.

Key Differences Between Docstrings and Markdown Docs

Key Differences Between Docstrings and Markdown Docs

The location difference matters most practically. Docstrings travel with your code. You update a function, the docstring is right there reminding you to update it too. Markdown files are separate. Easy to forget. Easy to let drift out of sync.
But markdown gives you space. Room for tutorials. Screenshots. Architecture diagrams. Stuff that doesn't belong crammed into a function definition.

When to Use Docstrings

Write docstrings for anything other developers will call directly.
API documentation for functions, classes, and methods. If it's public, it needs a docstring. Full stop. Someone will import it and wonder what it does.

Parameter descriptions and return types. What does this function accept? What comes back? Don't make people read your implementation to figure this out.

Code examples for specific functions. Short examples showing basic usage. Not full tutorials. Just enough to understand the pattern.

Type hints and signatures. Modern Python uses type hints directly, but docstrings can elaborate when types alone don't tell the story.

Auto-generated API reference. Tools like Sphinx and mkdocstrings pull docstrings into searchable documentation. Write good docstrings once, get API docs forever.

Here's my strong opinion: docstrings are mandatory for public APIs. Not optional. Not "nice to have." Mandatory. If you publish a library without docstrings, you're making everyone's life harder including your own in six months.

When to Use Markdown Documentation

Markdown handles everything that doesn't fit in a docstring.

README files and project overviews. What is this project? Why does it exist? How do I install it? First thing anyone sees on GitHub.

Getting started guides and tutorials. Walk through a complete workflow. Multiple functions working together. Real use cases.

Architecture and design decisions. Why did you structure things this way? What are the trade-offs? Where are the extension points?

Changelog and release notes. What changed in version 2.0? What broke? What's deprecated?

User guides and how-to articles. How do I accomplish this specific task? Step-by-step instructions with context.

Contributing guidelines. How do I set up the development environment? What's the PR process? Code style requirements?

None of this belongs in docstrings. You'd end up with function documentation that's 500 lines long. Nobody wants that.

Can You Use Both Together?

Yes. You should use both together. They're complementary.
The workflow looks like this:

Write docstrings for all your public code. Every function, every class, every method that someone might import.

Use tools like mkdocstrings or Sphinx to auto-generate API reference documentation from those docstrings. Write once, publish automatically.
Create markdown docs for everything else. Tutorials that show functions working together. Guides that explain concepts. READMEs that welcome newcomers.

Link between both documentation types. Your tutorial mentions a function? Link to the API reference. Your API docs show a function? Link to the relevant tutorial.

Modern documentation setups make this seamless. MkDocs with mkdocstrings can pull your Python docstrings directly into your markdown documentation site. You get narrative docs and API reference living together.
Example structure:


  index.md           # Project overview
  getting-started.md # Installation and first steps
  tutorials/
    basic-usage.md   # Walk-through tutorial
  api/
    reference.md     # Auto-generated from docstrings

Enter fullscreen mode Exit fullscreen mode

The API reference page literally pulls from your docstrings. Update your code, rebuild the docs, everything stays in sync.

Tools That Bridge Docstrings and Markdown

Several tools exist specifically to connect docstrings with markdown documentation.

MkDocs + mkdocstrings is my current favorite for Python projects. MkDocs builds the documentation site from markdown. mkdocstrings adds the ability to pull docstrings directly into those markdown pages. Clean, modern, works well.

Sphinx is the traditional Python documentation tool. More powerful. Steeper learning curve. Originally used reStructuredText but handles Markdown now with extensions. Powers the documentation for most major Python projects.

pdoc takes a lightweight approach. Point it at your Python package, get HTML documentation from your docstrings. Minimal configuration. Good for smaller projects.

JSDoc does similar work for JavaScript. Parses specially formatted comments and generates HTML documentation.

Javadoc is the Java ecosystem standard. Same concept. Comments in specific format, tool extracts and builds documentation.

All these tools extract docstrings and generate markdown or HTML documentation. Write your docstrings well and the tooling handles the publishing.

Best Practices for Developer Documentation

Write docstrings for all public APIs. Every function, class, and method that's part of your public interface. No exceptions.
Keep docstrings concise and technical. Parameters, return values, brief description of behavior. This isn't the place for lengthy explanations or background context.

Use markdown for narrative and tutorials. Anything that needs more than a paragraph of explanation belongs in external documentation.
Maintain consistency in formatting. Pick a docstring style. Stick with it across the project. Pick a markdown structure. Stick with that too.
Auto-generate API docs from docstrings. Don't manually duplicate information. Let tools do that work. You'll forget to update manual docs. Tools don't forget.

Version control both types together. Documentation lives in the same repo as code. Same commits. Same branches. Same review process.

Common Mistakes to Avoid

Duplicating information across docstrings and markdown. If you describe a function in detail in both places, one will become outdated. Use docstrings for API reference, link to them from markdown.

Writing lengthy tutorials in docstrings. I've seen docstrings with 200 lines of examples and explanations. That's not a docstring anymore. That's a tutorial crammed into the wrong place.

Neglecting to update docstrings when code changes. Function signature changed but docstring still describes the old parameters. Classic. Review docstrings during code review.

Creating markdown docs without linking to API reference. Your tutorial mentions five functions but doesn't link to their documentation. Users have to hunt around. Make it easy.

Using inconsistent documentation styles. One function uses Google style docstrings. Another uses NumPy style. A third uses some homebrew format. Pick a standard, enforce it.

Should I write docstrings or markdown documentation first?

Write docstrings first. They're coupled to your code. When you write a function, write the docstring immediately. It takes thirty seconds and you understand the function right now.

Markdown docs come later. Once you have working code with docstrings, you can write tutorials and guides that reference that documented API. The docstrings provide the foundation.

Do I need both docstrings and README files?

Yes. They serve completely different purposes.
Docstrings document your code's API. What does this function take? What does it return? How do I call it correctly?
README provides project overview. What is this project? How do I install it? Show me a quick example. Point me to more documentation.
Different audiences. Different needs. Both required for any serious project.

Can docstrings contain markdown formatting?

Yes. Most modern documentation tools support markdown syntax within docstrings.

Sphinx handles it with extensions. MkDocs and mkdocstrings process markdown in docstrings by default. pdoc supports it too.

You can use code blocks, bold text, lists, links. The documentation generator renders it properly. Just don't go overboard. Docstrings should stay concise.

What's the difference between docstrings and comments?

Docstrings are user-facing API documentation. They describe what code does from an external perspective. Call help() on a function and you see its docstring.

Comments are developer notes explaining implementation. Why this algorithm? Why this workaround? Internal context for future maintainers.

def process_data(items):
    """Process items and return cleaned results."""  # Docstring
    # Using set() here to remove duplicates efficiently  # Comment
    unique = set(items)
    return list(unique)
Different purposes. Different audiences. Both valuable.

Enter fullscreen mode Exit fullscreen mode

How do I convert docstrings to markdown documentation?

Use documentation generators designed for this.

For Python: mkdocstrings, Sphinx, or pdoc. Point the tool at your package, configure output format, run the generator. It extracts docstrings and produces markdown or HTML.

For JavaScript: JSDoc parses your comments and generates documentation.
The process is automated. Write docstrings following the expected format, run the tool, get documentation.

Which docstring format should I use?

For Python, use Google style or NumPy style. Both are widely supported by documentation tools. Both are readable.

Google style is more compact:

def example(param1, param2):
    """Brief description.

    Args:
        param1: Description of param1.
        param2: Description of param2.

    Returns:
        Description of return value.
    """

Enter fullscreen mode Exit fullscreen mode

NumPy style is more verbose but clearer for complex scientific parameters:

def example(param1, param2):
    """Brief description.

    Parameters
    ----------
    param1 : type
        Description of param1.
    param2 : type
        Description of param2.

    Returns
    -------
    type
        Description of return value.
    """

Enter fullscreen mode Exit fullscreen mode

Pick one. Use it everywhere. Consistency matters more than which specific style you choose.