ソースコードのコメントの形式って言語ごとにいろいろありますが、どういう形式が一番使われてるのか気になったので調べてみようと思いました。
Monaco Editorのソースコード見ると、https://github.com/microsoft/monaco-editor/blob/495d075be0f9e134fe659c0210cb777372c61899/src/basic-languages/typescript/typescript.ts#L12 のように、言語ごとにコメントのフォーマット書いてあるのでこれを集計します。
(VSCodeで調べたほうがもっと良い結果を得られると思いますが、スクリプトでチャチャっと調べるのはCDN使ってMonaco Editorをロードしたほうが楽だったのでこうしました。)
ラインコメント
単一行コメントのランキングです。
-
1位:
// ...
使用言語数: 38 (言語Id: apex, bicep, cameligo, c, cpp, csharp, cypher, dart, ecl, flow9, fsharp, go, java, javascript, kotlin, less, msdax, objective-c, pascal, pascaligo, php, postiats, powerquery, proto, pug, qsharp, rust, scala, scss, sol, aes, st, swift, systemverilog, verilog, typescript, typespec, wgsl) -
2位:
# ...
使用言語数: 16 (言語Id: azcli, coffeescript, elixir, graphql, hcl, ini, mips, perl, pla, powershell, python, r, ruby, shell, sparql, yaml) -
3位:
-- ...
使用言語数: 5 (言語Id: lua, mysql, pgsql, redshift, sql) -
4位:
' ...
使用言語数: 2 (言語Id: sb, vb) -
5位:
; ...
使用言語数: 1 (言語Id: scheme) -
5位:
;; ...
使用言語数: 1 (言語Id: clojure) -
5位:
* ...
使用言語数: 1 (言語Id: abap) -
5位:
COMMENT ...
使用言語数: 1 (言語Id: lexon) -
5位:
REM ...
使用言語数: 1 (言語Id: bat)
ラインコメントなし
言語数: 17 (言語Id: csp, css, dockerfile, freemarker2, handlebars, html, julia, liquid, m3, markdown, mdx, razor, redis, restructuredtext, tcl, twig, xml)
ブロックコメント
複数行かけるコメントのランキングです。
-
1位:
/* ... */
使用言語数: 37 (言語Id: apex, bicep, c, cpp, csharp, css, cypher, dart, ecl, flow9, go, hcl, java, javascript, kotlin, less, msdax, mysql, objective-c, pgsql, php, powerquery, proto, redshift, rust, scala, scss, sol, aes, sql, swift, systemverilog, verilog, typescript, typespec, vb, wgsl) -
2位:
(* ... *)
使用言語数: 6 (言語Id: cameligo, fsharp, m3, pascaligo, postiats, st) -
3位:
<!-- ... -->
使用言語数: 4 (言語Id: html, markdown, razor, xml) -
4位:
### ... ###
使用言語数: 2 (言語Id: coffeescript, mips) -
5位:
--[[ ... ]]
使用言語数: 1 (言語Id: lua) -
5位:
''' ... '''
使用言語数: 1 (言語Id: python) -
5位:
{ ... }
使用言語数: 1 (言語Id: pascal) -
5位:
{{!-- ... --}}
使用言語数: 1 (言語Id: handlebars) -
5位:
{/* ... */}
使用言語数: 1 (言語Id: mdx) -
5位:
{# ... #}
使用言語数: 1 (言語Id: twig) -
5位:
#| ... |#
使用言語数: 1 (言語Id: scheme) -
5位:
<-- ... -->
使用言語数: 1 (言語Id: freemarker2) -
5位:
<# ... #>
使用言語数: 1 (言語Id: powershell) -
5位:
=begin ... =end
使用言語数: 1 (言語Id: ruby)
ブロックコメントなし
言語数: 24 (言語Id: abap, azcli, bat, clojure, csp, dockerfile, elixir, graphql, ini, julia, lexon, liquid, perl, pla, pug, qsharp, r, redis, restructuredtext, sb, shell, sparql, tcl, yaml)
あとがき
僕がSQL書いてる時ときどきうっかり//
ってコメントアウトしちゃうのは//
が圧倒的にメジャーだからいけないんだ!という言い訳の材料にできそうです。
にしてもブロックコメントの種類多いな。