Comments in Code and Config Files: Notes Your Future Self Will Thank You For
What code comments are, how different file types mark them, and how to write comments that actually help.
A comment is text in a file that the computer ignores, written for humans. Good comments explain why something is the way it is.
How different files mark comments
| File type | Comment style |
|---|---|
| Python, shell scripts, YAML, .env | starts with # |
| INI files | starts with ; or # |
| JavaScript, Java, C | two slashes for a line comment, or slash-asterisk to asterisk-slash for a block |
| CSS | slash-asterisk to asterisk-slash blocks only |
| HTML and XML | text placed between an opening marker and a closing marker made of angle brackets and double hyphens |
| SQL | -- for a line |
| JSON | no comments allowed |
Because styles differ, check what the file type allows before adding one.
What makes a good comment
- Explain why, not what. The code shows what it does; a comment should say why.
- Be short. One or two lines.
- Stay accurate. Update or delete comments when the code changes.
- Avoid stating the obvious. "Add one to x" next to x = x + 1 helps nobody.
Examples
Weak:
# set timeout to 30
timeout = 30
Better:
# The server can take up to 30 s to respond during backups
timeout = 30
Marking changes
When you edit a file on the go, a dated note helps:
# 2027-03-10: changed port from 8080 to 9000 (conflict with other app)
Notes for yourself
Common markers:
| Marker | Meaning |
|---|---|
| TODO | something to do later |
| FIXME | something broken to fix |
| NOTE | something important to remember |
Search for them later to find unfinished work.
Commenting out
You can comment out a line to disable it temporarily, without deleting it. This is a safe way to test a change: put a comment marker at the start of the line, and remove it to bring the line back.
Keep a copy
Before changing an important file, save a backup copy.
The habit
A comment written today saves confusion later. Even a short note is better than none.
Notepad+ Text Editor
A fast, advanced text editor for notes and code, with emoji support
More about Notepad+ Text Editor
Drafting Emails in a Text Editor First
Why drafting important emails in a separate text editor prevents accidental sends, improves clarity and helps you write calmer messages.
Read article →Keeping a CV in Plain Text for Easy Updates
Maintain a master CV in a plain-text file so you can update it anywhere, tailor it quickly and paste it cleanly into online application forms.
Read article →Keeping a Work Diary for Performance Reviews
Record your achievements, feedback and challenges throughout the year in a simple text file, so performance reviews and promotions are easier to prepare.
Read article →Outlining a Novel in a Text Editor
Use a plain-text outline to plan characters, chapters and plot for a novel — flexible, searchable and easy to rearrange.
Read article →