improve the comment radio & supply systematic comment for hard-part module/function/handle-flow
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
For history code format and style, TiDB has always been pursuing the concept of agile and simpllicity development. It will not be stingy in exploring cutting-edge technologies worldwide, but it lacks the right amount of code-friendly comment indication.
No matter for the coming letters or for the existing co-workers, being familiar with non-your-business scope always take a lot of time out of learning purpose or collaborative development.
Let's go through several open-sourced database's code, check what's their comment radio is.
### CRDB
```
➜ cockroach git:(master) ✗ cloc ./
32056 text files.
26534 unique files.
6125 files ignored.
5 errors:
Line count, exceeded timeout: ./vendor/golang.org/x/net/idna/tables10.0.0.go
Line count, exceeded timeout: ./vendor/golang.org/x/net/idna/tables11.0.0.go
Line count, exceeded timeout: ./vendor/golang.org/x/net/idna/tables12.0.0.go
Line count, exceeded timeout: ./vendor/golang.org/x/net/idna/tables13.0.0.go
Line count, exceeded timeout: ./vendor/golang.org/x/net/idna/tables9.0.0.go
github.com/AlDanial/cloc v 1.98 T=37.74 s (703.0 files/s, 227375.0 lines/s)
---------------------------------------------------------------------------------------
Language files blank comment code
---------------------------------------------------------------------------------------
Go 17152 629128 989110 4974963
C 1558 67283 80832 372457
Markdown 795 43356 54 138255
C/C++ Header 1035 27904 64803 125728
C++ 734 25065 27540 119962
JSON 238 41 0 104306
TypeScript 980 9599 13820 100069
Starlark 1338 2898 1476 71937
Text 238 12710 0 69513
XML 206 3893 80 64114
Assembly 105 7733 3957 52684
Bourne Shell 432 8038 6143 46372
YAML 314 3814 2140 45924
yacc 13 5694 3299 38668
Protocol Buffers 183 4932 17611 16252
Expect 40 1319 1201 13375
reStructuredText 123 4540 1880 13338
HTML 77 1346 45 11310
Python 108 2484 3312 10454
CSV 19 0 0 8721
SQL 108 384 682 7844
diff 25 354 2788 7726
TeX 8 1656 611 6741
m4 9 577 605 5250
PO File 2 1900 2192 5226
Tcl/Tk 70 1232 580 5134
SCSS 74 733 207 4757
make 90 1112 851 4417
Stylus 94 925 887 4406
WiX include 10 133 206 2324
Perl 25 404 911 1898
CMake 54 390 892 1801
HCL 6 278 52 1499
ERB 6 271 5 1447
TOML 24 129 206 1407
Bazel 3 257 190 1316
JavaScript 28 227 576 1245
Windows Resource File 8 187 174 1175
MSBuild script 5 0 0 1169
Bourne Again Shell 23 183 169 1077
SVG 48 1 18 942
Windows Module Definition 11 45 70 810
INI 14 56 0 759
PlantUML 11 144 0 684
Dockerfile 22 122 172 611
awk 8 62 115 555
CSS 3 37 0 491
Java 7 82 332 471
Ruby 3 111 45 419
C# 1 31 10 393
D 1 2 0 335
Smarty 1 6 0 335
Thrift 1 155 610 303
Visual Studio Solution 7 7 7 258
Logos 2 28 11 234
WiX source 1 34 36 213
vim script 4 70 25 195
Flatbuffers 4 100 310 184
C Shell 1 3 3 148
Lisp 3 18 45 104
IDL 2 11 0 91
Elixir 4 4 1 85
PowerShell 1 31 11 76
DOS Batch 3 12 36 73
lex 1 14 12 55
Ant 1 10 32 46
sed 1 0 1 41
WiX string localization 1 15 21 34
PHP 1 4 1 30
Maven 1 5 0 28
Visual Basic 1 8 25 17
XSLT 1 0 0 10
LESS 1 1 13 4
Fortran 77 1 0 0 2
Standard ML 1 0 0 1
---------------------------------------------------------------------------------------
SUM: 26534 874338 1232049 6475298
---------------------------------------------------------------------------------------
```
### MySQL
```
➜ mysql-server git:(trunk) cloc ./
35884 text files.
12904 unique files.
21902 files ignored.
github.com/AlDanial/cloc v 1.98 T=9.69 s (1332.1 files/s, 657247.0 lines/s)
---------------------------------------------------------------------------------------
Language files blank comment code
---------------------------------------------------------------------------------------
C++ 4501 437960 563134 2357445
C/C++ Header 5305 202596 516370 895603
C 609 59256 75186 335625
Text 186 10188 0 164093
JSON 69 3 0 115233
Pascal 264 18268 35792 105702
Bourne Shell 118 14914 17661 93241
Java 534 12915 21441 55213
m4 23 4045 958 37151
CMake 451 5972 14138 36082
SQL 204 2310 6340 26792
Perl 122 7797 5269 25211
XML 57 727 422 22567
JavaScript 162 1989 2130 12257
Protocol Buffers 84 1788 5443 6620
make 20 399 345 3906
Puppet 22 0 162 3835
CSS 5 460 160 2089
Markdown 18 615 4 1729
Starlark 9 178 154 1718
Logos 4 142 84 1289
Bazel 2 119 120 1168
Windows Module Definition 9 31 107 789
Ant 2 141 359 780
yacc 2 146 77 771
Python 4 156 92 572
awk 5 27 95 533
HTML 5 44 77 531
reStructuredText 12 172 0 506
lex 3 211 123 501
YAML 10 22 181 474
Properties 21 68 779 469
SWIG 1 116 226 355
INI 15 73 0 333
Assembly 1 87 158 331
CSV 5 0 0 286
SQL Stored Procedure 5 38 0 248
LLVM IR 1 44 0 231
DOS Batch 3 43 89 230
PowerShell 1 42 9 221
Bourne Again Shell 5 46 157 216
Windows Resource File 7 45 145 207
Ruby 5 17 10 192
ERB 1 39 0 160
AsciiDoc 2 61 0 130
Lisp 1 46 85 96
NAnt script 1 30 0 76
WiX source 1 18 19 72
vim script 1 13 42 50
Visual Studio Solution 1 0 1 24
Windows Message File 3 6 50 18
Visual Basic 1 0 0 15
Dockerfile 1 1 3 8
---------------------------------------------------------------------------------------
SUM: 12904 784424 1268197 4313994
---------------------------------------------------------------------------------------
```
### TiDB
```
➜ tidb git:(master) cloc ./
4896 text files.
4613 unique files.
408 files ignored.
github.com/AlDanial/cloc v 1.98 T=2.88 s (1600.3 files/s, 590448.5 lines/s)
--------------------------------------------------------------------------------
Language files blank comment code
--------------------------------------------------------------------------------
Go 2919 108778 111350 978889
JSON 118 119 0 332191
Text 3 5 0 45883
Starlark 564 883 20 31323
SQL 381 45 92 25905
Markdown 136 6148 24 15356
yacc 2 809 601 15344
Bourne Shell 224 2422 3432 8725
TOML 145 1122 518 4268
YAML 14 63 180 1598
CSV 51 1 0 1394
TypeScript 18 215 239 1371
make 4 147 62 517
Bourne Again Shell 9 59 132 370
XML 1 0 0 216
diff 6 23 195 203
Bazel 1 18 2 116
Protocol Buffers 2 24 56 113
SVG 4 0 0 113
Dockerfile 5 28 56 106
JavaScript 1 1 3 34
Smarty 1 3 0 28
INI 2 3 0 19
HTML 1 0 0 14
Groovy 1 2 0 9
--------------------------------------------------------------------------------
SUM: 4613 120918 116962 1464105
--------------------------------------------------------------------------------
```
### Conclusion
CRDB = comment/code = (989110+80832+64803) /(4974963+372457+125728) = 20.7%
MySQL = comment/code = (563134+516370+ 75186) /(2357445+895603+335625) = 32.1%
TiDB = comment/code =(111350/978889) = 11.3%
we are not emphasize that high comment radio can always lead a robust code quality, but a more friendly open-source code style is. Why Postgres enjoys a global reputation and has become the primary research object of academic research over the years. First part of it is that the quality of its code commits is very high without the compromise and burden of industrial implementation. Second part of it is that the academic code style makes reading clear. We can not control the first part of it, but we can start from second part. **Clear code does not necessarily imply high quality, but high-quality code must be clear code.**
Contributor guide
Assessment
This issue has not been assessed yet.