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
- line:
//ActionScript line comment
Algol
- block:
comment ALGOL block comment ;
APL
Like all things in APL, it uses a Weird Symbol.
- line:
⍝APL line comment
Assembly
Depending on the assembly "flavor" comments may or may not be delimited by the following:
- line:
;Assembly line comment
- line:
//Assembly line comment
- block:
/*Assembly line comment*/
BASIC
In BASIC REM
probably stands for remark
.
- line:
REM BASIC LINE COMMENT
Batch
Batch is what the command line shell language for Windows is sometimes called.
- line:
rem Batch line comment
C
C originally only had block comments, but now supports C++ style
comments.
- block:
/*C-style block comment*/
- line:
//C++ style line comment
CSS
- block:
/*CSS block comment*/
Common Lisp
- line:
;Common Lisp line comment
C++
Exactly the same as C. More info can be found at cppreference.
- block:
/*C-style block comment*/
- line:
//C++ style line comment
D
D nesting block comments may contain other comment types.
- block:
/*D block comment*/
- block-style (nesting):
/+D nesting block comment+/
- line:
//D line comment
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.
- cell-style:
'Excel comment
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.
- block:
( Forth block comment )
Go
Go uses C style and C++ style comments.
- block:
/*Go-style block comment*/
- line:
//Go style line comment
G-code
- block:
(G-code block comment)
HTML
HTML comments are notoriously hard to for some people to remember, because of the long sequence of special characters.
- block:
<!--HTML block comment-->
Haskell
- block:
{-Haskell block comment-}
Java
Java comments are the same as in C and in C++.
- block:
/*Java block comment*/
- line:
//Java line comment
JavaScript
JavaScript comments are exactly the same as in C and in C++.
- block:
/*JavaScript block comment*/
- line:
//JavaScript line comment
Joy
- block:
(*Joy block comment*)
Lua
- line:
--Lua line comment
- block:
--[[Lua block comment]]
Pascal
- block:
(*Pascal block comment*)
- block:
{Pascal block comment}
Perl
- line:
#Perl line comment
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!
- block:
/*PHP block comment*/
- line:
//PHP line comment
- line:
#PHP line comment
Python
Python technically only has line-style comments, but docstrings can be used as block-style comments.
- line:
#Python line comment
- block:
"""Python docstring comment"""
- block:
'''Python docstring comment'''
Ruby
- block:
=begin Ruby block comment =end
- line:
#Ruby line comment
Rust
Rust has doc comments in addition to normal comments. Nested block comments are supported.
- block:
/*Rust block comment*/
- line:
//Rust line comment
Smalltalk
Smalltalk does not use double quotes for strings.
- block:
" Smalltalk block comment "
XML
XML comments are just like HTML comments.
- block:
<!--XML block comment-->
Zig
Zig also supports doc comments.
- line:
//Zig line comment
- doc-style:
///Zig doc comment
This page was last updated on 2024.02.26.