Page 1 of 2
[Minor request] Compiler counts useless lines
Posted: Sun Sep 19, 2021 4:52 am
by BarryG
Why does the compiler count empty (blank) lines as part of the total line count in the compiling dialog? Seems useless, and I'd rather know how many actual code lines have been parsed. The compiler doesn't parse blank lines, so why is it incrementing the counter when it's ignoring them? Same for lines with only comments, too.
Re: [Minor request] Compiler counts useless lines
Posted: Sun Sep 19, 2021 9:59 am
by STARGĂ…TE
Good hint. But if you go in this way, I would prefer to count the characters or better the tokens.
Counting only the lines or characters hides the true complexity, but counting the tokens give the same value:
Code: Select all
If Decision = "Strings should also count as one."
ThisIsAVeryLongVariableNameAndShouldBeCountAsOneToken = 4
Else
ThisIsAVeryLongVariableNameAndShouldBeCountAsOneToken = 9
EndIf
Lines = 5 ; Tokens = 16 ; Characters = 182
Code: Select all
If D = "Short" : T = 4 : Else : T = 9 : EndIf
Lines = 1 ; Tokens = 16 ; Characters = 45
Re: [Minor request] Compiler counts useless lines
Posted: Sun Sep 19, 2021 1:36 pm
by Tenaja
(deleted)
Re: [Minor request] Compiler counts useless lines
Posted: Sun Sep 19, 2021 3:54 pm
by skywalk
Comments are code too. How did they get in your source code?

Re: [Minor request] Compiler counts useless lines
Posted: Sun Sep 19, 2021 9:55 pm
by BarryG
Why does nobody understand my point? This info is collected during compilation - a second pass isn't needed.
Re: [Minor request] Compiler counts useless lines
Posted: Mon Sep 20, 2021 12:13 am
by Tenaja
(deleted)
Re: [Minor request] Compiler counts useless lines
Posted: Mon Sep 20, 2021 12:23 am
by Demivec
It doesn't matter what lines the compiler counts. It's compiling. The code that comes out is not what goes in.
Anybody that measures their code's effectiveness, completeness, accuracy, difficulty, or whatever simply by the number of lines is already using a flawed metric.
It doesn't matter what the compiler counts as it compiles because it won't make the compilation any faster simply because it isn't counting as high.
I'm not speaking against the request but I am speaking in favor of the OP opinion that this is definitely 'no biggie'.
It seems like it serves no useful purpose outside of tickling individuals who are statistic hounds.
Re: [Ignore]
Posted: Mon Sep 20, 2021 3:43 pm
by Tenaja
(deleted)
Re: [Ignore]
Posted: Mon Sep 20, 2021 5:02 pm
by AZJIO
Delete the comments.
It should be borne in mind that this is suitable for a simple combination of quotation marks. When using a tilde (~), the number of quotation marks is not controlled.
https://www.purebasic.fr/english/viewto ... 76#p584676
Code: Select all
EnableExplicit
Declare.s RegexReplace2(RgEx, *Result.string, Replace0$, Once = 0)
Define FilePath$, FilePath2$
Define Text.string
FilePath$ = OpenFileRequester("Open file", GetCurrentDirectory(), "PureBasic (*.pb)|*.pb", 0)
If Asc(FilePath$) And FileSize(FilePath$) > 0
FilePath2$ = Left(FilePath$, Len(FilePath$) - 3) + " (no comments).pb"
Else
End
EndIf
#File = 0
ReadFile(#File, FilePath$)
Text\s = ReadString(#File, #PB_UTF8 | #PB_File_IgnoreEOL) + #CRLF$
CloseFile(#File)
#q$ = Chr(34)
If FindString(Text\s, "~" + #q$)
MessageRequester("",
"Code contains strings with escaped quotes: ~" + #q$ + "..." + #q$ + #CRLF$ +
"A copy of the file is being created, check the correctness of these lines in it.")
EndIf
#RegExp = 0
If CreateRegularExpression(#RegExp , ~"(?m)^((?:[^''\";]*([''\"]).*?\\2)*[^;]*)\\h*;.*$" )
RegexReplace2(#RegExp, @Text, "\1")
FreeRegularExpression(#RegExp)
If CreateRegularExpression(#RegExp , "(\r\n|\r|\n){2,}" )
RegexReplace2(#RegExp, @Text, "\1")
FreeRegularExpression(#RegExp)
EndIf
If CreateRegularExpression(#RegExp , "(?<!\r)\n" )
Text\s = ReplaceRegularExpression(#RegExp, Text\s, #CRLF$)
FreeRegularExpression(#RegExp)
EndIf
If CreateFile(#File, FilePath2$)
WriteStringFormat(#File, #PB_UTF8)
WriteString(#File, Text\s, #PB_UTF8)
CloseFile(#File)
EndIf
EndIf
; https://www.purebasic.fr/english/viewtopic.php?p=575871#p575871
Procedure.s RegexReplace2(RgEx, *Result.string, Replace0$, Once = 0)
Protected i, CountGr, Pos, Offset = 1
Protected Result$, Replace$
Protected NewList item.s()
Protected LenT, *Point
CountGr = CountRegularExpressionGroups(RgEx)
If CountGr > 9
CountGr = 9
EndIf
If ExamineRegularExpression(RgEx, *Result\s)
While NextRegularExpressionMatch(RgEx)
Pos = RegularExpressionMatchPosition(RgEx)
Replace$ = ReplaceString(Replace0$,"\0", RegularExpressionMatchString(RgEx))
For i = 1 To CountGr
Replace$ = ReplaceString(Replace$, "\"+Str(i), RegularExpressionGroup(RgEx, i))
Next
If AddElement(item())
item() = Mid(*Result\s, Offset, Pos - Offset) + Replace$
EndIf
Offset = Pos + RegularExpressionMatchLength(RgEx)
If Once
Break
EndIf
Wend
If AddElement(item())
item() = Mid(*Result\s, Offset)
EndIf
LenT = 0
ForEach item()
LenT + Len(item())
Next
*Result\s = Space(LenT)
*Point = @*Result\s
ForEach item()
CopyMemoryString(item(), @*Point)
Next
FreeList(item())
EndIf
EndProcedure
Re: [Minor request] Compiler counts useless lines
Posted: Mon Nov 08, 2021 4:37 am
by BarryG
Just revisiting this topic since a similar one was just posted (
viewtopic.php?f=3&t=78179).
All I want to know is this: in the following dialog box, where is the line count coming from?
Since PureBasic is a one-pass compiler, then I assume it's reading each source line from top-down, correct? So when it gets a line, it currently increments the count as shown in the dialog, yeah? So why can't it just NOT update the dialog when a blank line (and comment) is found? What am I missing?
Re: [Minor request] Compiler counts useless lines
Posted: Mon Nov 08, 2021 11:56 am
by jacdelad
Please don't grab the torches and pitchforks, but I have to ask: Why is it important to know how many lines of your project are actually code? Are you "paid per line"?
Re: [Minor request] Compiler counts useless lines
Posted: Mon Nov 08, 2021 12:34 pm
by Axeman
It's not important bud, just interesting. If someone is curious about how much actual code they've written for a project then having a way to get that information is useful to them and harmless to everyone else.
There may be situations where knowing the number of actual code lines in a project is essential, however. There are a lot of different people using Purebasic in different ways. Having extra information that doesn't add clutter is always good either way.
I'm not sure why this is so contentious. It's a weird thing for people to argue against.
Re: [Minor request] Compiler counts useless lines
Posted: Mon Nov 08, 2021 1:29 pm
by BarryG
jacdelad wrote: Mon Nov 08, 2021 11:56 amWhy is it important to know how many lines of your project are actually code?
Three main reasons:
(1) It shows the correct actual count, because I hate incorrect/illogical values.
(2) Some gaming contests are based on your entry having no more than X lines of code.
(3) Users of the demo version may want to know when the 800-line limit is approaching (and can't see because of IncludeFiles).
And yes, some people could be "paid per line" for all we know.
To me, it looks like a bug/oversight in the dialog line count. All I'm asking for is a fix. It is a weird thing for people to argue against.
Re: [Minor request] Compiler counts useless lines
Posted: Mon Nov 08, 2021 1:42 pm
by Tenaja
I think this could also be handy. Even GitHub does it, and it is nice to know if there's any actual code below the license.
Re: [Minor request] Compiler counts useless lines
Posted: Mon Nov 08, 2021 1:46 pm
by Marc56us
Create a program and set it as tool with 'before compile' starting mode.
(This way those who don't need this feature won't see the compilation slowed down for statistics)
PS.
- Don't forget to follow XInclude files
- Count ':' as new line
