Tabs versus Spaces

The indentation of source code is always a controversially discussed topic. Some prefer spaces, while others like tabs. And those who have no clue, don't even care about such ridiculous things like code formatting at all.

Some insightful wisdom on this topic is shared in the CodingStyle document of the Linux kernel:

"Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3. [...]

Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read [...]. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning."

And yes, avoiding deep indentation is always a good thing to increase code karma, because flat is better than nested in most situations.

So with all that said, below are some numbers and charts for a small selection of highly successful open source projects. The source code of these projects was inspected line by line. Each line was then counted into one of the following categories: NOT, TABS, SPACES, BOTH or BLOCK_COMMENT. And for lines with trailing spaces, the TRAILING category was updated additionally. The BLOCK_COMMENT category is a special one and only used for languages which support block comments. A line belongs to the BLOCK_COMMENT category if it begins with a block comment or is part of one. The used block comment detection is not perfect, but good enough for most cases.

The program for doing all of this is also available: VoidMeter.

P.S. Personally, I like tabs.

Ant

Project Home http://ant.apache.org/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.8.2 1191 254380 36561 103 119332 44 98340 496
1.7.1 1123 237281 34551 97 109012 51 93570 214
1.6.5 954 206001 30993 60 97439 12 77497 151
1.5.4 728 173080 22454 226 70285 78 80037 4389

Ant 1.8.2

Apache

Project Home http://httpd.apache.org/
Inspected Files [".c", ".h"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
2.2.17 818 343635 90512 1253 176808 588 74474 3860
2.2.12 811 336566 88721 2080 171156 1830 72779 3925
2.2.6 783 314531 82811 2067 158363 1833 69457 3509
2.2.0 783 310283 81833 2071 156012 1827 68540 3425
2.0.64 716 272008 74639 4028 127018 2044 64279 6815
2.0.63 714 268998 73785 4855 123613 3293 63452 7010
2.0.61 714 268841 73772 4855 123543 3293 63378 7022
1.3.42 222 110748 29525 10400 38261 5578 26984 1582

Apache 2.2.17

Django

Project Home http://www.djangoproject.com/
Inspected Files [".py"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.3 1645 177229 47490 0 129732 7 0 639
1.2.5 1530 155572 42228 0 113344 0 0 760
1.2.4 1523 153842 42176 0 111665 1 0 799
1.2.3 1451 149897 57078 0 92818 1 0 899
1.2.2 1450 149681 57219 0 92461 1 0 899
1.2.1 1431 147471 57815 0 89656 0 0 879
1.2 1431 147384 57780 0 89604 0 0 889
1.1.4 1166 132178 52815 0 79363 0 0 785
0.96.5 283 35161 8605 0 26555 1 0 292

Django 1.3

Gradle

Project Home http://gradle.org/
Inspected Files [".java", ".groovy"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
0.9.2 2326 220759 51731 3 113218 0 55807 573
0.9.1 2274 218038 51143 3 111717 0 55175 598
0.9 2267 216797 50842 3 110903 10 55039 607
0.8 1418 130846 31028 20 64695 27 35076 534
0.7 1101 92156 23107 20 46430 26 22573 499
0.6 955 81123 20347 91 40467 2 20216 468
0.5 646 57011 14049 2 28414 2 14544 341

Gradle 0.9.2

Grails

Project Home http://www.grails.org/
Inspected Files [".java", ".groovy"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.3.7 1453 189297 42336 1909 102912 357 41783 925
1.3 1441 182945 41119 16621 81438 2583 41184 4883
1.2.5 1443 182060 40937 16966 80013 2772 41372 4972
1.2 1405 176119 39664 16075 77427 2596 40357 4770
1.1.2 1266 153743 35164 12965 68315 1710 35589 3942

Grails 1.3.7

Groovy

Project Home http://groovy.codehaus.org/
Inspected Files [".java", ".groovy"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.7.10 2080 304811 48853 27665 161641 335 66317 7127
1.7.5 2031 300137 48004 27560 157632 288 66653 7030
1.7.0 1895 280573 45291 30279 148317 2276 54410 8562
1.6.9 1855 266958 42861 30107 139472 2259 52259 7915
1.6.5 1806 262445 42205 30068 136789 2255 51128 7851
1.6.0 1750 254365 41020 30002 132524 1883 48936 8028
1.5.8 1479 209600 32079 29602 103778 1928 42213 7791
1.5.4 1405 198078 30191 29064 97047 1728 40048 7828
1.5.0 1368 191779 28652 29045 93297 1882 38903 7908

Groovy 1.7.10

Jetty

Project Home http://jetty.codehaus.org/jetty/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
7.3.1 836 192775 37339 321 116611 708 37796 11547
7.2.2 805 185528 36068 275 111874 680 36631 11129
7.1.6 766 175035 34358 303 104531 646 35197 10201
7.0.2 727 166370 31246 149 101648 316 33011 12236
6.1.26 716 164066 30197 496 97051 463 35859 12626
6.0.2 427 95593 16500 924 51953 489 25727 8417
5.1.15 461 109431 18989 638 58438 453 30913 7284
4.2.27 442 103896 15238 1555 54537 808 31758 7807

Jetty 7.3.1

JRuby

Project Home http://www.jruby.org/
Inspected Files [".java", ".rb"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.6.0 4930 875656 183977 11689 622037 6447 51506 24857
1.5.6 4484 808096 169265 10606 571229 6221 50775 24645
1.5.0 4476 806648 168933 10599 570308 6176 50632 24634
1.4.1 4525 778621 164395 10545 555000 6255 42426 27059
1.4.0 4525 778621 164395 10545 555000 6255 42426 27059
1.3.1 4413 766626 160514 10117 548698 6144 41153 30893
1.3.0 4412 766532 160505 10117 548611 6146 41153 30894

JRuby 1.6.0

Jython

Project Home http://www.jython.org/
Inspected Files [".g", ".java", ".py"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
2.5.2 2743 790436 199030 1752 572820 376 16458 2900
2.5.1 2545 773882 194101 3042 562289 284 14166 2746
2.5.0 2511 769120 192635 4262 557742 441 14040 3162
2.2.1 1932 347604 103566 14534 217547 1240 10717 2436
2.1 383 92180 19431 7796 52371 976 11606 664
2.0 322 74170 14813 4270 44779 1836 8472 2241

Jython 2.5.2

Linux

Project Home http://www.kernel.org/
Inspected Files [".c", ".h", ".S"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
2.6.38.1 30547 13289726 4368948 6090642 288273 479121 2062742 39808
2.6.35.11 28306 12255811 4002864 5592294 292134 445103 1923416 38115
2.6.34.8 27405 11866177 3877806 5405735 277303 433993 1871340 38150
2.6.33.8 26768 11571099 3781074 5262820 275427 425892 1825886 37802
2.6.32.35 25864 11252579 3680896 5123674 285355 390901 1771753 38283
2.6.27.58 20759 8699716 2869725 3984441 200498 299908 1345144 41631
2.4.37.11 11170 5166168 1656233 2121689 315461 188492 884293 144393
2.4.0 7142 3158568 1010623 1269334 248503 116933 513175 95030
2.2.26 5154 2526629 774058 1037737 213052 95416 406366 87944
2.2.0 4002 1676184 530538 663496 143098 66784 272268 56846
2.0.40 1992 951383 280064 339187 121488 43137 167507 23892
2.0.34 1844 854360 250111 305235 108243 39360 151411 22480

Linux 2.6.38.1

Maven

Project Home http://maven.apache.org/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
3.0.3 848 115087 27012 45 61867 122 26041 1258
3.0 830 111581 26230 45 59770 122 25414 1212
2.2.1 386 61368 14180 35 36705 19 10429 1029
2.2.0 380 60469 13978 35 36186 19 10251 964
2.0.11 361 53087 12635 45 30601 18 9788 533
2.0.3 570 68857 16337 16 40093 27 12384 895

Maven 3.0.3

MyBatis / iBatis

Project Home http://www.mybatis.org/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
3.0.4 861 76511 21667 385 48133 55 6271 195
3.0.3 821 74059 20938 385 46571 49 6116 130
3.0.2 800 72764 20571 385 45721 43 6044 77
3.0.1 791 71636 20330 346 44913 3 6044 67
2.3.5 289 33337 6873 285 18218 149 7812 457
2.3.4 338 37529 8057 181 21278 113 7900 442
2.3.3 489 108002 18293 1747 73628 202 14132 3125
2.3.2 735 172009 28701 2551 120520 283 19954 5644
2.3.1 581 115020 20458 1720 78007 202 14633 3136
2.3.0 533 82511 15003 1864 51260 212 14172 3759

MyBatis 3.0.4

Python

Project Home http://www.python.org/
Inspected Files [".c", ".h", ".py"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
3.2 2222 895098 254147 4022 589312 3248 44369 27218
3.1.3 2201 833203 243803 2824 545352 2441 38783 22367
3.0.1 2076 778840 230262 98597 404354 9169 36458 23644
2.7.1 2870 1123077 345679 4015 722310 3273 47800 25345
2.6.6 2622 1027818 322547 2837 658733 2461 41240 22105
2.5.5 2339 901702 292439 154898 391391 26190 36784 20955
2.4.6 2061 768203 259853 147559 311546 23071 26174 16900
2.3.7 2034 697629 225075 171983 252704 19429 28438 22308

Python 3.2

Ruby on Rails

Project Home http://rubyonrails.org/
Inspected Files [".rb"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
3.0.5 1327 176488 34368 6 142101 5 8 69
3.0.0 1316 172597 33745 6 138833 5 8 24
2.3.11 1339 188954 36788 34 151997 25 110 3141
2.3.2 1256 173388 30064 10 143208 10 96 2355
2.2.3 1139 161043 28008 8 132919 10 98 2520
2.1.2 1052 149051 25527 52 123325 49 98 3930
2.0.5 792 116005 21107 61 94671 44 122 3758

Rails 3.0.5

Ruby

Project Home http://www.ruby-lang.org/
Inspected Files [".c", ".h", ".rb"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.9.2-p180 2644 1233594 273030 58991 825312 21282 54979 880
1.9.2-p0 2600 1224854 271499 58891 818424 21251 54789 672
1.9.1-p431 2322 1059886 230945 39624 716361 19713 53243 17424
1.9.1-p0 2316 1054137 229176 39219 714050 19472 52220 17447
1.9.0-5 2319 788078 196862 40047 480002 19627 51540 17477
1.9.0-0 2111 635207 167615 38943 364194 17717 46738 17472
1.8.7-p334 1947 535817 140393 32437 307034 14020 41933 17189
1.8.4 1825 469910 126001 32641 262762 12750 35756 16667
1.8.0 801 256980 73341 34035 118171 15134 16299 5312

Ruby 1.9.2-p180

Steel Bank Common Lisp

Project Home http://www.sbcl.org/
Inspected Files [".c", ".h", ".lisp"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.0.46 1021 456564 111321 0 339513 0 5730 0
1.0.45 1022 459731 112895 0 341093 0 5743 0
1.0.36 1017 452489 111042 0 335741 0 5706 0
1.0.27 1008 443935 109362 0 328906 0 5667 0
1.0.18 995 436251 107444 0 323349 0 5458 0
1.0.9 985 430035 105394 0 319292 0 5349 0
1.0 944 376737 102090 0 269558 0 5089 0

SBCL 1.0.46

Stripes

Project Home http://www.stripesframework.org/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.5.6 310 47054 8289 230 21596 20 16919 705
1.5.3 296 44367 7842 234 20400 20 15871 639
1.5 287 42047 7475 240 18867 23 15442 602
1.4.3 252 31392 5972 64 13170 34 12152 40
1.4 245 30091 5752 41 12435 0 11863 30
1.3.2 210 25386 4990 42 10222 0 10132 22
1.3 210 25284 4976 42 10150 0 10116 22

Stripes 1.5.6

Tomcat

Project Home http://tomcat.apache.org/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
7.0.11 1378 363385 59502 0 184033 0 119850 15815
7.0.6 1371 361113 59241 0 182250 0 119622 15741
6.0.32 1153 339716 58038 4360 161645 2026 113647 15159
6.0.0 1103 316108 56996 7893 145420 2595 103204 14579
5.5.33 1476 392476 69954 4192 181793 2479 134058 18535
5.5.0 1152 309537 60408 8104 129860 5286 105879 15504
5.0.30 1160 316690 62557 8295 133961 5403 106474 15406
5.0.0 1067 314365 57088 9012 105560 6151 136554 13529

Tomcat 7.0.11

Whitespace Examples

Project Home http://compsoc.dur.ac.uk/whitespace/examples.php
Inspected Files [".ws"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
0.3 7 953 136 63 111 643 0 819
0.2 5 661 98 39 72 452 0 565

Whitespace 0.3

Wicket

Project Home http://wicket.apache.org/
Inspected Files [".java"]
Lines indented by
Version Files Lines Not Tabs Spaces Both Block comment Trailing
1.4.16 2180 308814 50095 130616 122 13 127968 10965
1.4.11 2141 303457 49221 128108 122 17 125989 10796
1.4.5 2097 295734 48049 124421 271 14 122979 10546
1.4.0 2073 293911 47722 124145 117 14 121913 10460
1.3.7 1949 274979 44912 114583 134 15 115335 9483
1.3.4 1938 271746 44389 112769 179 5 114404 9360
1.3.0 1896 264806 43255 109503 12 4 112032 9303

Wicket 1.4.16