Code measurement software lines - are comments included?

As a hobby project and as a training exercise, I decided to implement programmatic strings for measuring script code in Python.

However, I have a question:

  • Are comments taken into account in the dimension?
  • The approach I followed: open the file, read it from beginning to end, count the number of lines. If comments should be ignored, skip this line, otherwise continue and increase the counter. Is this done?

Please note that I know that many tools exist and may be better than mine ( sloccount is one example), however I do this as a complete hobby program.

+4
source share
3 answers

Usually you do not consider comments as a line of code, but this can be a useful metric, so perhaps you should keep track of their number when analyzing the file.

You better check lines that are not spaces, and end CRLF without continuing the char line. Regex says that this means you want to avoid such lines (assuming backslash is a continuation of your char line):

 \\\s*\n\r 

if you find such a line, do not increase the counter. Of course, a regular expression may vary depending on which language (engine) you use, and using a regular expression may not even be the most appropriate way - a simple state mechanism might be better.

+2
source
  • Not
  • What if the logical line of code is completed?
+1
source

Unable to use simple bash command, use bash command in Python script, import os command and: :)

0
source

All Articles