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

推荐订阅源

云风的 BLOG
云风的 BLOG
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Announcements
Recent Announcements
爱范儿
爱范儿
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Latest
Security Latest
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cisco Talos Blog
Cisco Talos Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
Check Point Blog
T
Threat Research - Cisco Blogs
I
Intezer
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
T
Tenable Blog
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Spread Privacy
Spread Privacy
GbyAI
GbyAI
T
Tailwind CSS Blog
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
NISL@THU
NISL@THU
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
K
Kaspersky official blog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Proofpoint News Feed
S
SegmentFault 最新的问题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
The Hacker News
The Hacker News
博客园 - 【当耐特】
Cyberwarzone
Cyberwarzone
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
V
Vulnerabilities – Threatpost
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
博客园 - 叶小钗

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Docstrings vs Markdown Docs: What Should Developers Actually Write?
Anoop Kumar Paul · 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)`

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])

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

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.

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.
    """

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.
    """

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