Lines of code

Is there a way to obtain the total lines of code in a Xojo project - quickly?

not really

Some statistics would be nice though…

for me,I would like to have a feature in a pure text model.

I’m not sure how useful such a thing would be, but you could save the project in text format (Xojo Project) and then count the lines in the Xojo files with something like this in Terminal:

( find ./ -name '*.xojo*' -print0 | xargs -0 cat ) | wc -l

This will count the “lines” for the UI definitions, though, so it’s a bit inflated.

You can get close though. Print the project to a pdf and multiply the number of pages by the number of lines per page.

or for that matter XJPRINT at least shows line numbers on its output :slight_smile:

That means printing from the ‘App’ object? That prints only the code in App, or do you have to select all objects?

[quote=271251:@Paul Lefebvre]I’m not sure how useful such a thing would be, but you could save the project in text format (Xojo Project) and then count the lines in the Xojo files with something like this in Terminal:

( find ./ -name '*.xojo*' -print0 | xargs -0 cat ) | wc -l

This will count the “lines” for the UI definitions, though, so it’s a bit inflated.[/quote]
That’s for Mac OSX I guess.

You want to select no project items, so try selecting something like “This Computer” in build settings and then choosing File->Print.

Mac, Linux, maybe Windows 10 Tech Preview with Bash installed.

I started a project I called the Xojo Project Tool. It looks at a VCS project, can alphabetize it, and being to sync two projects, but one of the other things it does is count lines of code. It makes some assumptions, for example, menu items count as 1 line of code. Controls count as 3 lines of code (figure the name, caption, placement in other languages), Classes get 2 lines of code, properties/constants get 1 line of code, etc…

You can download it at:

https://github.com/jcowgar/xpt

I am not actively working on the project, but it may be of interest to someone.

$ xpt --help

Help:
  -h, --help           Show help
  --sort=STR           Sort items in the project (Folder/Module name or all)
  --sync               Synchronize items from various projects
  --count-loc          Count the number of lines of code
  --recursive          Perform the operation recursively
  --simulate           Display the resulting manifest instead of saving it to disk
  --verbose            Produce verbose output

$ xpt --count-loc xpt.xojo_project
 Source Line Count:   1,746
Comment Line Count:   1,022
 Comment to Source:     37%
       Total Count:   2,768

$ xpt --count-loc --verbose xpt.xojo_project
   Code | Comment |   Total |  C-C% | File
--------------------------------------------------
    236 |     210 |     446 |   47% | App
     74 |      16 |      90 |   18% | FolderItemHelpers
     14 |       0 |      14 |    0% | FormatCodePreferences
    143 |     235 |     378 |   62% | OptionParser.Option
      2 |       7 |       9 |   78% | OptionParser.OptionInvalidKeyValueException
      2 |       3 |       5 |   60% | OptionParser.OptionMissingKeyException
    724 |     399 |   1,123 |   36% | OptionParser.OptionParser
      6 |      11 |      17 |   65% | OptionParser.OptionParserException
      2 |       4 |       6 |   67% | OptionParser.OptionUnrecognizedKeyException
     66 |       0 |      66 |    0% | StringHelper
      2 |       0 |       2 |    0% | Xpt
     52 |      18 |      70 |   26% | Xpt.XContainer
     19 |       0 |      19 |    0% | Xpt.XContainerIterator
     98 |      31 |     129 |   24% | Xpt.XManifest
      2 |       0 |       2 |    0% | Xpt.XManifestClass
      2 |       0 |       2 |    0% | Xpt.XManifestFolder
      2 |       0 |       2 |    0% | Xpt.XManifestInterface
    111 |      20 |     131 |   15% | Xpt.XManifestItem
      2 |       0 |       2 |    0% | Xpt.XManifestMenu
      2 |       0 |       2 |    0% | Xpt.XManifestModule
    183 |      68 |     251 |   27% | Xpt.XManifestSourceItem
      2 |       0 |       2 |    0% | Xpt.XManifestWindow
--------------------------------------------------
  1,746 |   1,022 |   2,768 |   37% | Total

I should say, Class Definitions get 2 lines of code, i.e. Start/End in other languages. Obviously functions, properties, constants and everything else inside of the class gets their full line count…

Getting the lines of code is possible with Arbed. You need a special script AFAIR.

LOC isn’t that useful a measure of complexity which is often much more instructive

And depending on how you use measures like LOC you might be rewarding the wrong behaviour or this

http://www.bkeeney.com/rb-code-reports-version-3/

Here’s a decent article about measuring code complexity

You could ask @Thomas Tempelmann for wether Arbed could show some counts like number of methods and line count.

XJprint is really nice!
I don’t use it everyday but when it’s needed it works for stuff like this.

RB Code Reports is not for sale any longer. Sorry.

is this the kind of thing you are looking for?

www.rdS.com/Project_Analysis.html

This topic got me thinking… and since I’m still unemployed :frowning: , I have free time on my hands

unlike XJPrint that requires the VCS format of an XOJO project, the app that does this just needs the XML version

There are a number of factors that went in to pulling it. Part of it is the small market. Part of it was the original developers design decisions and part of it was the ever changing document format of Xojo project files.

To get it to where we wanted it was way more work than I was wiling to put into it. People will buy a $20 utility but they wouldn’t an $80 utility and even then I doubt we’d make enough to justify the development time. It would be different if we found it useful in looking at our consulting projects but it just didn’t add any value. So unlike Shorts where we use it in a lot of different situations, RB Code Reports doesn’t add value to us.

If someone wants to buy the rights to it I’d be willing to talk.

[quote=271321:@Dave S]is this the kind of thing you are looking for?

www.rdS.com/Project_Analysis.html

This topic got me thinking… and since I’m still unemployed :frowning: , I have free time on my hands

unlike XJPrint that requires the VCS format of an XOJO project, the app that does this just needs the XML version[/quote]

if anyone is interested in a copy of the app that can produce this, let me know… I just have to add a dialog box and a bit of spit and polish