by Breck Yunits
July 13, 2022 — About 85% of the languages in PLDB have line comments.
A language supports line comments if it defines a special token (nowadays usually //
or #
) where everything after that token until the end of the line becomes a comment. Example:
print "Hello world" # this is a comment
These are different from multiline comments which are delimited by a pair of tokens (such as %{
and }%
).
38% of programming languages follow C and use //
. C (1972) follows B (1969) which follows BCPL (1966).
22% use #
, which has become very popular thanks to languages like Python, Perl, and Ruby.
The SQL languages all generally use --
.
The era of experimentation with line comment tokens appears to be over: the last time a new line comment token appeared in the top 250 was 1993.
About 15% of the languages in PLDB don't support line comments. These include some of the key markups for the web like HTML, CSS and SVG.
JSON famously does not support comments. But a number of its derivatives do, such as JSON with Comments.
A few general purpose languages don't support line comments including Mathematica and OCaml.
Like everything, there are exceptions to the common cases. A few languages, such as SPSS, have a more restrictive form of line comment where the line comment token has to be the first token on the line.
A few languages also support multiple line comment tokens. The Ini config format supports both ;
and #
.