Liste des Groupes | Revenir à co vms |
On 4/16/2025 9:29 PM, Dan Cross wrote:In article <67fee5b8$0$708$14726298@news.sunsite.dk>,>
Arne Vajhøj <arne@vajhoej.dk> wrote:There is no question that it is most accurate to only
count the continued line as one in your example.
>
But I suspect that a lot of LOC counters just count
non-blank and non-comment.
>
Anything else requires language knowledge.
>
And while it for Fortran, Basic, Macro-32 may be relative
simple, then for other languages it can become more tricky.
>
Let us take 4 times Pascal:
>
if a = 1 then b := 2 else b := 3;
>
if a = 1 then
b := 2
else
b := 3;
>
if a = 1 then begin
b := 2;
end else begin
b := 3;
end;
>
if a = 1 then
begin
b := 2;
end
else
begin
b := 3;
end;
>
How many lines? I would say that the most correct is 3 in
all 4 cases. But coding the line counter to return that
would require it to have Pascal knowledge.
>
And what about the fluent style that are so modern?
>
o = f.create();
o.add(1);
o.add(2);
o.add(3);
>
o = f.create()
.add(1)
.add(2)
.add(3);
>
o = f.create().add(1).add(2).add(3);
>
1 1 1 or 4 1 1 or 4 4 1 or 4 4 4??
>
So I think counters go for the simple approach and assume
that for large code bases with many developers then total
converge towards an "average" style.
Most modern code-counting tools _are_ language aware. Whether
they do a better or worse job for each given language may be a
matter of debate, but most at least recognize different
languages and have some knowledge of their semantics.
Cf, https://github.com/XAMPPRocky/tokei?tab=readme-ov-file
https://github.com/AlDanial/cloc?tab=readme-ov-file#recognized-languages-
https://github.com/boyter/scc/blob/master/LANGUAGES.md
etc.
Their language awareness consist of recognizing comments.
>
They are examples of some of those tools that simply count
non-blank non-comment lines.
>
(SCC also know some keywords but that is used for complexity
calculation not for line counting)
>
C:\Work>type demo.c
// C demo
>
#include <stdio.h>
>
int main()
{
int a[] = {
1,
2,
3
};
printf("%d %d %d\n",
a[0],
a[1],
a[2]);
return 0;
}
>
C:\Work>cloc-1.96 demo.c
1 text file.
1 unique file.
0 files ignored.
>
github.com/AlDanial/cloc v 1.96 T=0.01 s (67.5 files/s, 1147.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment
code
-------------------------------------------------------------------------------
C 1 2 1
14
-------------------------------------------------------------------------------
>
C:\Work>scc demo.c
───────────────────────────────────────────────────────────────────────────────
Language Files Lines Blanks Comments Code
Complexity
───────────────────────────────────────────────────────────────────────────────
C 1 17 2 1 14
0
───────────────────────────────────────────────────────────────────────────────
Total 1 17 2 1 14
0
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop (organic) $305
Estimated Schedule Effort (organic) 0.63 months
Estimated People Required (organic) 0.04
───────────────────────────────────────────────────────────────────────────────
Processed 200 bytes, 0.000 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
>
C:\Work>tokei-x86_64-pc-windows-msvc demo.c
===============================================================================
Language Files Lines Code Comments
Blanks
===============================================================================
C 1 17 14 1
2
===============================================================================
Total 1 17 14 1
2
===============================================================================
Les messages affichés proviennent d'usenet.