Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line counter for ASP.NET

Tags:

c#

asp.net

I know the number of lines of code is completely arbitrary and a horrible metric. Even so, after a long day I like to click a little button and see that my pet project grew by 10%. (Or if I spent the day refactoring yet again it slimmed down by 10%, woohoo!)

I've used two line counters that can analyze code from CodeProject in the past, but they only handle .cs files, completely dismissing my extensive work in .aspx, .asmx, .js, .css, etc.

Has anyone used a line counter that could parse all the text files usually found on a typical ASP.NET site?

Update

CMS recommended CLOC, which was indeed exactly what I was looking for. Here's my output for the curious. It even counted my MSBuild script!

C:\Web>cloc-1.06.exe --exclude-dir=.svn,bin,images AST
     474 text files.
     474 unique files.
   28254 files ignored.

http://cloc.sourceforge.net v 1.06  T=70.0 s (6.3 files/s, 737.7 lines/s)
-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
C#                  332      4670      9666     21255 x   1.36 =       28906.80
ASP.Net              91        58         0      4053 x   1.29 =        5228.37
Javascript            9      1262      2112      4011 x   1.48 =        5936.28
CSS                   5       193        42      1665 x   1.00 =        1665.00
MSBuild scripts       1         0         7      1413 x   1.90 =        2684.70
HTML                  2       126         5       429 x   1.90 =         815.10
XML                   1         0         0       392 x   1.90 =         744.80
PHP                   1        21        13       249 x   3.50 =         871.50
-------------------------------------------------------------------------------
SUM:                442      6330     11845     33467 x   1.40 =       46852.55
-------------------------------------------------------------------------------
like image 734
DavGarcia Avatar asked Jan 23 '23 22:01

DavGarcia


2 Answers

Give a look to CLOC

Check the output:

-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
ASP.Net              21       290         0      3424 x   1.29 =        4416.96
XML                   1         0         0        26 x   1.90 =          49.40
DOS Batch             1         1         0         8 x   0.63 =           5.04
C#                    1         0         0         4 x   1.36 =           5.44
-------------------------------------------------------------------------------
SUM:                 24       291         0      3462 x   1.29 =        4476.84
-------------------------------------------------------------------------------

You can check also other code counters:

  • SLOCCount
  • sclc
  • USC's CODECOUNT
  • loc
  • Ohcount
like image 112
Christian C. Salvadó Avatar answered Jan 26 '23 12:01

Christian C. Salvadó


You might be able to get the same level of satisfaction from counting passing unit tests. While this number, too, can be misleading, at least the unit tests (if not simply done to increase your count) have some valid bearing on the quality of your code.

like image 37
tvanfosson Avatar answered Jan 26 '23 10:01

tvanfosson