100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

Software Documentation

Learn the major types of software documentation and how each serves a distinct audience and purpose.

Software Quality & MaintenanceBeginner9 min readJul 8, 2026
Analogies

Introduction

Software documentation is any written material that explains how code works, how to use it, or why it was built a certain way. Good documentation reduces onboarding time, prevents repeated mistakes, and preserves institutional knowledge that would otherwise live only in the heads of the original authors. Documentation is not one uniform thing, though — different audiences need different kinds of information, and conflating them (for example, writing API reference material inside a README meant for new contributors) makes documentation harder to find and maintain.

🏏

Cricket analogy: A team keeps separate materials for separate audiences: a scouting report for the coach, a simplified rulebook for junior players, and match footage archives for analysts, rather than one giant folder mixing them all together.

Explanation

Code comments and docstrings live directly alongside the code and explain the 'why' behind non-obvious implementation choices, or describe a function's inputs, outputs, and side effects for anyone reading or calling it in an IDE. They are aimed at developers actively working in that specific file or function, and they should be kept close enough to the code that they stay in sync with it — comments that explain what the code obviously does, rather than why a tricky decision was made, tend to go stale and add noise. API documentation describes the public contract of a library, service, or endpoint: what operations are available, what parameters they take, what they return, what errors are possible, and any usage constraints such as authentication or rate limits. It is aimed at consumers of the API who may never read the underlying source code, so it needs to be accurate, complete, and often includes example requests and responses. README and onboarding documentation sits at the root of a project and answers the first questions a new developer or user has: what does this project do, how do I install and run it, how do I run the tests, and who do I ask for help. It is a map, not an encyclopedia — it should link out to deeper documentation rather than trying to contain everything. Architecture Decision Records (ADRs) capture significant design decisions at the point they are made: the context/problem, the options considered, the decision taken, and the consequences and tradeoffs accepted. Unlike a README, which describes the current state, an ADR is a historical record — it explains why the system looks the way it does, which prevents future engineers from re-litigating settled decisions or accidentally undoing them without understanding the original reasoning.

🏏

Cricket analogy: Comments are like a captain's field-placement note scribbled for the bowler mid-over explaining why a fielder moved; the API docs are like the printed scorecard rules everyone consults without watching practice; the README is the ground's welcome signage pointing newcomers to the pavilion; the ADR is the archived match report explaining why a captaincy decision was made years ago so it isn't second-guessed blindly.

Example

python
def calculate_shipping_cost(weight_kg: float, distance_km: float) -> float:
    """Calculate shipping cost in USD for a package.

    Uses a tiered rate table rather than a flat per-kg rate because
    carriers apply volume discounts above 20kg (see ADR-0007 for the
    full rationale and the rejected flat-rate alternative).

    Args:
        weight_kg: Package weight in kilograms. Must be > 0.
        distance_km: Shipping distance in kilometers. Must be >= 0.

    Returns:
        Estimated shipping cost in USD, rounded to 2 decimal places.

    Raises:
        ValueError: If weight_kg is not positive.
    """
    if weight_kg <= 0:
        raise ValueError("weight_kg must be positive")

    # Carriers give a volume discount above 20kg; without this branch
    # heavy packages are overcharged relative to the carrier's actual
    # invoice (see ADR-0007).
    rate_per_kg = 0.40 if weight_kg > 20 else 0.55
    base_cost = weight_kg * rate_per_kg
    distance_cost = distance_km * 0.01
    return round(base_cost + distance_cost, 2)


# --- Excerpt from docs/api/shipping.md (API documentation) ---
# POST /v1/shipping/estimate
# Body: { "weight_kg": number, "distance_km": number }
# Returns: { "cost_usd": number }
# Errors: 400 if weight_kg <= 0

# --- Excerpt from README.md ---
# ## Quick start
# 1. pip install -r requirements.txt
# 2. pytest              # run the test suite
# 3. python app.py       # start the local server
# See docs/architecture/ for design decisions (ADRs).

# --- Excerpt from docs/adr/0007-shipping-rate-tiers.md ---
# # ADR-0007: Use tiered shipping rates instead of a flat rate
# Status: Accepted
# Context: Flat per-kg rate overcharged heavy packages vs carrier invoices.
# Decision: Apply a discounted rate above 20kg.
# Consequences: Slightly more complex pricing logic; matches carrier billing.

Analysis

Notice how each artifact in the example targets a different reader and stays scoped to its purpose. The docstring and the inline comment serve someone reading or calling calculate_shipping_cost directly in their editor: the docstring gives the formal contract (types, error conditions, return value), while the inline comment explains the non-obvious 'why' of the discount branch — pure restatement like '# multiply weight by rate' would have added noise instead of value. The API documentation excerpt is written for a consumer who will never open this Python file at all; they only need the HTTP contract. The README excerpt is deliberately shallow — it gets a new developer running the code in three steps and then points elsewhere rather than duplicating the API or architecture details. The ADR is the only artifact that explains why the tiered-rate design was chosen over the simpler flat-rate alternative; if that reasoning lived only as a code comment, it would be easy to miss when someone later considers 'simplifying' the pricing logic back to a flat rate without realizing that decision was already made and rejected for a documented reason. Keeping these four types separate, rather than merging them into one giant document, means each one stays a manageable size and each reader finds exactly the altitude of detail they need.

🏏

Cricket analogy: In a real match report, the bowler's private note on grip stays in the dressing room, the umpire's rulebook goes to officials, the scoreboard is a quick summary for fans, and the selectors' archived memo on why a batting order changed prevents future selectors from reverting it without knowing why.

Key Takeaways

  • Code comments/docstrings explain 'why' and document contracts for developers reading the code directly.
  • API documentation describes the public contract for consumers who never see the source.
  • README/onboarding docs are a concise map to get new developers running quickly, linking to deeper docs.
  • Architecture Decision Records preserve the historical reasoning behind significant design choices.
  • Keeping documentation types separate and scoped prevents any single document from becoming unmaintainable.

Practice what you learned

Was this page helpful?

Topics covered

#Python#SoftwareEngineeringStudyNotes#SoftwareEngineering#SoftwareDocumentation#Software#Documentation#Explanation#Example#StudyNotes#SkillVeris