What does Visual Studio Code Analysis Lines of Code do with HTML, CSS and Javascript?
Asked Answered
B

4

9

I know that Lines of Code (LoC) is a dubious if not false code metric and there are lots of posts to this effect.

However ... I still have to provide a LoC count for a web site in a report.

I was using the Visual Studio 2010 Code Analysis Code Metrics feature to get the LoC when I wondered what does it do with or how does it count HTML, CSS and Javascript?

The VS Help text provides this description of the metric -

Lines of Code – Indicates the approximate number of lines in the code. The count is based on the IL code and is therefore not the exact number of lines in the source code file. A very high count might indicate that a type or method is trying to do too much work and should be split up. It might also indicate that the type or method might be hard to maintain.

So my multi part question is ... does HTML, CSS, Javascript get compiled to IL and if it does then should I assume it is included in the VS LoC metric? If it does not get compiled to IL, what is the best way to calculate or include HTML, CSS and Javascript in the LoC metric for my report? Or should they even be included in LoC at all?

Bilk answered 26/1, 2012 at 0:12 Comment(0)
D
2

Does HTML, CSS, Javascript get compiled to IL?

No - those files are static. The only time they get compiled is if you compose them in code behind and add them to the Response buffer directly.

If it does not get compiled to IL, what is the best way to calculate or include HTML, CSS and Javascript in the LoC metric for my report? Or should they even be included in LoC at all?

I would say counting those files may not be of much use -- although getting a handle on JavaScript file size could be of importance as it would have some effect on page load times (larger files will take longer to download -- but unless you have 20K lines of JavaScript, it shouldn't be a huge difference).

There are a few tools out there that count lines of code for all file types. Microsoft's LOC counter is here. Also, tools like NDepend (which has a free trial) can count lines of code, too.

Delftware answered 26/1, 2012 at 0:24 Comment(4)
And what would be the difference if any of that was sent through a minimizer? Would they count it as one LOC?Firmament
@Firmament I guess it depends on how it minimizes it. I never really gave it a thought as I don't really focus on the number of JavaScript lines of code I have -- I usually focus more on the size of the files (and all resources) that I'm downloading to the client. Packing and compression are definitely in play in production for my applications.Delftware
@Positronium But minification only really removes whitespace and formatting, it does not change loops, if statements etc. You may have one very long line of text and less file size but the actual numbeer of code statements does not really change.Bilk
Scott, I know. Don't feed the troll ;)Positronium
P
11

I
think
it
does
not
count
them,
and
this
is
clearly
the
most
well
thought
out
response
in
the
history
of
Stack
Overflow
based
on
line
count.
Also
to
count
lines
in
your
JavaScript
files
try

find . -name '*.js' | xargs wc -l
Positronium answered 26/1, 2012 at 0:29 Comment(1)
Also, if you're on Windows as I suspect, try cygwin.Positronium
D
2

Does HTML, CSS, Javascript get compiled to IL?

No - those files are static. The only time they get compiled is if you compose them in code behind and add them to the Response buffer directly.

If it does not get compiled to IL, what is the best way to calculate or include HTML, CSS and Javascript in the LoC metric for my report? Or should they even be included in LoC at all?

I would say counting those files may not be of much use -- although getting a handle on JavaScript file size could be of importance as it would have some effect on page load times (larger files will take longer to download -- but unless you have 20K lines of JavaScript, it shouldn't be a huge difference).

There are a few tools out there that count lines of code for all file types. Microsoft's LOC counter is here. Also, tools like NDepend (which has a free trial) can count lines of code, too.

Delftware answered 26/1, 2012 at 0:24 Comment(4)
And what would be the difference if any of that was sent through a minimizer? Would they count it as one LOC?Firmament
@Firmament I guess it depends on how it minimizes it. I never really gave it a thought as I don't really focus on the number of JavaScript lines of code I have -- I usually focus more on the size of the files (and all resources) that I'm downloading to the client. Packing and compression are definitely in play in production for my applications.Delftware
@Positronium But minification only really removes whitespace and formatting, it does not change loops, if statements etc. You may have one very long line of text and less file size but the actual numbeer of code statements does not really change.Bilk
Scott, I know. Don't feed the troll ;)Positronium
J
1

Is HTML/CSS/JS compiled to IL? It's possible (and also a good idea) to compile HTML templates to IL but I doubt it's done in your case. Your files are probably just static and served on request.

Alternative? CodeAnalyze as in How do you count your Lines of Code?

Include HTML/CSS/JS in LoC? If you need this statistic to show how much you have done you might include all of them. If it's to get a rough idea of complexity I would only include Javascript files that you have written (exclude jQuery etc).

Jellybean answered 26/1, 2012 at 0:27 Comment(0)
G
0

It says right there that it's "based on the IL code". By definition then it cannot include non-IL languages such as HTML, CSS, and Javascript.

Not sure how you can come up with this count, but I would be concerned about whomever is requiring you to provide such a count -- it is a useless metric, particularly for those langauges.

Gearalt answered 26/1, 2012 at 0:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.