div0 icon

Comment Reference for Many Programming Languages

(For anyone who has ever asked how do I comment in this strange programming language?)

Comments: the part of programming that computers all but ignore. However, programmers should not ignore comments, in general, so here is a quick reference to comments for Many Programming Languages (30 total).

Line comments start with some string of characters and the comment continues until the next line is reached. Block comments start with some string of characters and the comment continues until another string of characters is reached.

Note: shell languages typically use # to start a line comment.

ActionScript

Algol

APL

Like all things in APL, it uses a Weird Symbol.

Assembly

Depending on the assembly "flavor" comments may or may not be delimited by the following:

BASIC

In BASIC REM probably stands for remark.

Batch

Batch is what the command line shell language for Windows is sometimes called.

C

C originally only had block comments, but now supports C++ style comments.

CSS

Common Lisp

C++

Exactly the same as C. More info can be found at cppreference.

D

D nesting block comments may contain other comment types.

Excel

Excel formulas can be used as string data instead by starting a cell value with a single quote. This method is not to be confused with Excel's actual comments.

Forth

Forth comments use the word named (, which must be surrounded by whitespace. However, these comments are usually used on a single line. The whitespace surrounding both parentheses is required.

Go

Go uses C style and C++ style comments.

G-code

HTML

HTML comments are notoriously hard to for some people to remember, because of the long sequence of special characters.

Haskell

Java

Java comments are the same as in C and in C++.

JavaScript

JavaScript comments are exactly the same as in C and in C++.

Joy

Lua

Pascal

Perl

PHP

PHP has C-style, C++ style, and Perl-style comments, and considering that PHP is often embedded inside of HTML, then it also has access to HTML-style comments, which means that a PHP file can have up to four different types of comments!

Python

Python technically only has line-style comments, but docstrings can be used as block-style comments.

Ruby

Rust

Rust has doc comments in addition to normal comments. Nested block comments are supported.

Smalltalk

Smalltalk does not use double quotes for strings.

XML

XML comments are just like HTML comments.

Zig

Zig also supports doc comments.


This page was last updated on 2024.02.26.