As mentioned in chapter Introduction and in contrast to other existing line counting tools, program Line Counter is able to find comments that are surrounded by “code”. For this purpose a special algorithm was developed and how this algorithm works is subject of this section. Furthermore, to visualize all explanations the comment types are used that typically appear in C/C++ and other common programming languages.
Generally spoken all comment types can be divided into two basic groups. These groups are single–line and multi–line comments. Single–line comments, on the one hand, starting on their specific open tag and ending at the end–of–line. Multi–line comments, on the other hand, also starting on their specific open tag but they end on their corresponding closing tag. This is of course a very strict approach of analyzing different comment types.
From a different perspective it becomes possible to divide comment types into “pure comments” and “code comments”. As the name suggests, pure comments include nothing else but comments. And in turn code comments include commented statements as well as something else that does not belong to this comment, the “code”.
With these indications in background the implemented algorithm has to decide between comment lines that can be counted and other lines that do contain comments but which cannot be counted. For this reason program Line Counter counts all in all four different comment type depending values, pure comment hits, pure comment lines, code comment hits and code comment lines.
Pure comment hits means in this case the number of comments of a specific type that contains commented statements. Pure comment lines, means in turn, the number of lines which are used by this particular pure comment type hit. Please note only the number of counted pure comment lines do affect the statistical evaluation.
In contrast to pure comment hits, code comment hits means the number of comments of a specific type that contains commented statements as well as something else that does not belong to this comment, such as code. Code comment lines means instead the number of lines that can be treated as a kind of pure comment lines. This means in fact that code comment lines also affect the statistical evaluation.
Now please take a closer look at table below which shows a set of comment types as well as their combinations. Please note this list just represents a subset of all possibilities and is therefore not complete.
Comment Type Combinations | Pure Comments | Code Comments | LOC | ||
---|---|---|---|---|---|
Hits | Lines | Hits | Lines | ||
Single Line Comments | |||||
//... | 1 | 1 | |||
/*...*/ | 1 | 1 | |||
code//... | 1 | 1 | 1 | ||
code/*...*/ | 1 | 1 | 1 | ||
/*...*/code | 1 | 1 | 1 | ||
code/*...*/code | 1 | 1 | 1 | ||
/*...*///... | 2 | 1* | |||
/*...*//*...*/ | 2 | 1 | |||
/*...*/code/*...*/ | 2 | 1 | |||
/*...*/code/*...*/code/*...*/ | 3 | 1 | |||
/*...*/code//... | 2 | 1 | |||
Multi Line Comments | |||||
/*... ... ...*/ |
1 |
1 1 1 |
|||
code/*... ... ...*/ |
1 |
1 1 |
1 |
||
/*... ... ...*/code |
1 |
1 1 |
1 |
||
code/*... ... ...*/code |
1 |
1 |
1 1 |
||
/*... ... ...*///... |
1 1 |
1 1 1* |
|||
code/*... ... ...*///... |
1 1 |
1 1* |
1 |
||
/*... ... ...*/code//... |
1 1 |
1 1 |
1 |
||
code/*... ... ...*/code//... |
1 1 |
1 |
1 1 |
As already mentioned table above shows only a subset of possible combinations of code and comments. The most important column of this table is column LOC which means “Lines Of Code”. In this column the number of lines is shown that contain comments but which affect the evaluation statistics as well.
Furthermore, no spaces are shown in table above. But this does not mean that spaces are not allowed. This wouldn’t make any sense because having spaces is the usual use case. And program Line Counter takes care about existing whitespaces between different comment types as well as between comments and code.
Copyright © plexdata.de