[Minor request] Compiler counts useless lines
[Minor request] Compiler counts useless lines
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.
Last edited by BarryG on Sat Oct 16, 2021 11:46 am, edited 4 times in total.
Re: [Minor request] Compiler counts useless lines
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:
Lines = 5 ; Tokens = 16 ; Characters = 182
Lines = 1 ; Tokens = 16 ; Characters = 45
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
Code: Select all
If D = "Short" : T = 4 : Else : T = 9 : EndIf
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: [Minor request] Compiler counts useless lines
(deleted)
Last edited by Tenaja on Mon Nov 08, 2021 1:38 pm, edited 1 time in total.
Re: [Minor request] Compiler counts useless lines
Comments are code too. How did they get in your source code?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: [Minor request] Compiler counts useless lines
Why does nobody understand my point? This info is collected during compilation - a second pass isn't needed.
Last edited by BarryG on Sat Oct 16, 2021 11:47 am, edited 2 times in total.
Re: [Minor request] Compiler counts useless lines
(deleted)
Last edited by Tenaja on Mon Nov 08, 2021 1:39 pm, edited 1 time in total.
Re: [Minor request] Compiler counts useless lines
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.
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]
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
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
Last edited by AZJIO on Thu May 26, 2022 1:22 pm, edited 3 times in total.
Re: [Minor request] Compiler counts useless lines
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?
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
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"?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: [Minor request] Compiler counts useless lines
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.
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
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.
Last edited by BarryG on Sun Dec 05, 2021 3:35 am, edited 1 time in total.
Re: [Minor request] Compiler counts useless lines
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
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
(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