Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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

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).

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top