Smart Apps Pro

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

  1. Explain why, not what. The code shows what it does; a comment should say why.
  2. Be short. One or two lines.
  3. Stay accurate. Update or delete comments when the code changes.
  4. 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.

Get Notepad+ Text Editor →

Notepad+ Text Editor app icon

Notepad+ Text Editor

A fast, advanced text editor for notes and code, with emoji support

Get the app

More about Notepad+ Text Editor