Beginner Topic 16 of 54 Programming Fundamentals
Comments and Documentation
Human-readable notes in code explaining intent.
How it works
Comments are ignored by the compiler and exist for humans, explaining why code does something rather than restating what it does. Docstrings and documentation comments attach structured descriptions to functions and classes so that tools can generate reference pages and IDE hints. Good documentation also includes a README, usage examples and notes on design decisions.
Step-by-step walkthrough
- Code says what happens.
- A comment explains why a surprising choice was made.
- A docstring documents inputs, outputs and errors of a function.
- A README tells newcomers how to install and use the project.
- Outdated comments mislead, so update them with the code.
Where it is used
API reference docs, explaining non-obvious decisions, marking TODOs and warnings, describing assumptions about inputs and onboarding new team members all depend on documentation. Examples in docs double as tests in some languages.
Common pitfall
Comments that restate the code, or that go stale after the code changes, are worse than none because they mislead. Commented-out code clutters files; version control already remembers it. Prefer clear naming first, and update comments in the same change as the code.
Where it fits in the course
Comments and Documentation is topic 16 of 54 in Programming Fundamentals, rated Beginner. It follows Scope. The next topic is Debugging Basics.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Programming Fundamentals quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Programming Fundamentals quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Comments and Documentation?
Where do people use Comments and Documentation?
What is the most common mistake with Comments and Documentation?
What should I learn before this topic?
How can I practice it?
Is Comments and Documentation hard to learn?
How long does it take to learn Comments and Documentation?
Which topics are related to Comments and Documentation?
What should I study after Comments and Documentation?
Related topics
- Scope (Programming Fundamentals)
- Debugging Basics (Programming Fundamentals)
- Return Values (Programming Fundamentals)
- Arrays and Lists (Programming Fundamentals)
- Software Documentation (Software Engineering)