-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
does-every-programming-language-support-line-comments.scroll
89 lines (67 loc) · 3.28 KB
/
does-every-programming-language-support-line-comments.scroll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
author https://github.com/breck7 Breck Yunits
date 2022.07.13
groups All
title Does every programming language have line comments?
import postHeader.scroll
printTitle
mediumColumns 1
printAuthor
image line-comments.png
About 85% of the languages in PLDB have line comments.
link BASE_URL/features/line-comments.html line comments
dateline
endSnippet
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:
code
print "Hello world" # this is a comment
These are different from multiline comments which are delimited by a pair of tokens (such as `%{` and `}%`).
link BASE_URL/features/multiline-comments.html multiline comments
## The majority of languages use // or # to start a line comment
*38%* of programming languages follow C and use `//`. C (1972) follows B (1969) which follows BCPL (1966).
link BASE_URL/concepts/c.html C
link BASE_URL/concepts/b.html B
link BASE_URL/concepts/bcpl.html BCPL
*22%* use `#`, which has become very popular thanks to languages like Python, Perl, and Ruby.
link BASE_URL/concepts/python.html Python
link BASE_URL/concepts/perl.html Perl
link BASE_URL/concepts/ruby.html 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.
## 15% of languages don't have line comments
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.
link BASE_URL/concepts/html.html HTML
link BASE_URL/concepts/css.html CSS
link BASE_URL/concepts/svg.html SVG
JSON famously does not support comments. But a number of its derivatives do, such as JSON with Comments.
link BASE_URL/concepts/json.html JSON
link BASE_URL/concepts/json-with-comments.html JSON with Comments
A few general purpose languages don't support line comments including Mathematica and OCaml.
link BASE_URL/concepts/mathematica.html Mathematica
link BASE_URL/concepts/ocaml.html OCaml
## A few exceptions
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.
link BASE_URL/concepts/spss.html SPSS
A few languages also support multiple line comment tokens. The Ini config format supports both `;` and `#`.
link BASE_URL/concepts/ini.html Ini config format
observable https://observablehq.com/@breck7/line-comments-in-programming-languages
ohayoCode
html.h1 Line comments
web.get https://pldb.io/languages.csv
filter.where rank < 300
columns.keep appeared title rank features.hasLineComments lineCommentToken
columns.rename features.hasLineComments hasLineComments
filter.where hasLineComments !=
tables.basic
group.by hasLineComments
tables.basic
filter.where hasLineComments = false
tables.basic
filter.where lineCommentToken !=
group.by lineCommentToken
reduce appeared min firstAppeared
roughjs.pie Line comment token usage
label lineCommentToken
value count
rows.sortByReverse count
tables.basic
import footer.scroll