Xojo Project Statistics

Does anyone know of a utility which will give you statistics for a Xojo project that you drop on it? I’m looking for things like number and types of files, methods, lines of code, etc. There was an old VisualStudio utility called CodeCount which was free and useful in this regard. I’m hoping to find something similar for Xojo. Any ideas?

Cheers.

-bill k

I suppose you have looked at Arbed http://www.tempel.org/Arbed ?

Arbed can do this with a special script. Now if I could remember how to use this:

[code]// Collects statistics on a project, including lines of code and comments
//
// For documentation see: http://www.tempel.org/Arbed/Scripting

// global variables for statistics
dim methodCount, emptyLineCount, codeLineCount, commentLineCount, ClassCount as Integer

// start iterating over all project items
dim root as PrjItem = PrjItemRoot()
traverse (root)

// print statistics
print "Classes: "+Str(ClassCount)
print "Methods: "+Str(methodCount)
print "Code lines: "+Str(codeLineCount)
print "Comment lines: "+Str(commentLineCount)
print "Empty lines: "+Str(emptyLineCount)
print "Total lines: "+Str(codeLineCount+commentLineCount+emptyLineCount)

sub traverse (parent as PrjItem)
dim item as PrjItem
dim iter as PrjItemIterator = parent.SubItems()
while iter.GetNextPrjItem(item) // loop over all members of “parent”

	'class?
	if item.IsOfType ("Class") then
		ClassCount = ClassCount + 1
	end
	
	if item.IsOfType ("MethodHeader") then
		// it's a method, an event handler or an event definition
		methodCount = methodCount + 1
		processMethod (item)
	end
	
	// look at item's member's, too (recursion)
	traverse (item)
wend

end sub

// A subroutine to count the source lines
sub processMethod (item as PrjItem)
dim src as String
if item.GetSource (src) then
// split the source into individual lines so that we can look at each line
dim lines() as String = src.Trim.Split (EndOfLine)

	// now count the code and comment lines
	for each line as String in lines
		line = line.Trim
		if line = "" then
			emptyLineCount = emptyLineCount + 1
		elseif line.Left(1) = "'" or line.Left(2) = "//" or line.Left(4) = "rem " then
			// this is a comment line
			commentLineCount = commentLineCount + 1
		else
			// this is a code line
			codeLineCount = codeLineCount + 1
		end
	next
end

end sub
[/code]

RB Code Reports was great for this

Unfortunately it seems to be no longer in development.

I am in the middle of a tool I call XPT, Xojo Project Tool, https://github.com/jcowgar/xpt

It will do various things, but it will give some statistics, for example:

$ xpt --count-loc --verbose ./xpt.xojo_project
   Code | Comment |   Total |  C-C% | File
--------------------------------------------------
    269 |     216 |     485 |   45% | App
     74 |      16 |      90 |   18% | FolderItemHelpers
     14 |       0 |      14 |    0% | FormatCodePreferences
    165 |     224 |     389 |   58% | OptionParser.Option
      2 |       7 |       9 |   78% | OptionParser.OptionInvalidKeyValueException
      2 |       3 |       5 |   60% | OptionParser.OptionMissingKeyException
    503 |     351 |     854 |   41% | OptionParser.OptionParser
      6 |      11 |      17 |   65% | OptionParser.OptionParserException
      2 |       4 |       6 |   67% | OptionParser.OptionUnrecognizedKeyException
     66 |       0 |      66 |    0% | StringHelper
      2 |       0 |       2 |    0% | Xpt
     55 |      18 |      73 |   25% | 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
    114 |      20 |     134 |   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
--------------------------------------------------

It is open source and I’d be happy if someone wants to contribute and expand the --count-loc option to include additional statistics (which should be fairly easy).

OH, the --count-loc does an intelligent line count, it does not simply count the number of lines in the file. For example, a form may have 30 lines for a single control. It’s smart about that. It is actually parsing the code contained in the files. I have no way of knowing how much you customized that control, but keeping along this example, it gives you (I think) 2 lines of code for each control on the window, assuming that it is at least the something equivalent of declaring a variable, setting its type, setting a property or two (caption for example on a label). The same with Menu Entries, etc… Methods, Events, etc… automatically get 2 LOC for the method declaration and end, then the number of lines of code contained within the method. Constants and Properties get a single line of code added to the total, Computed Properties are handled properly counting the LOC’s in the respective Get and Set methods, etc…

@Michel Bujardet: I’ve looked at Arbed and it doen’t seem to give me what I want. I actually have a license from last year’s OmegaBundle so I’ll need to explore this more, especially with @Beatrix Willius’s script example (though it seems like an awful lot of effort to go through to get basic project stats).

@Jeremy Cowgar: XPT looks closer to what I’m looking for, I hope that you get some help with this.

@Peter Fargo: Damn you Bob Keeney! Cutting down “RB Code Reports” in the prime of it’s life. Shame on you :slight_smile:

It was not in the prime of its life. It was on life support for a number of years before we stopped selling it. And I can’t open source it because there are too many proprietary things in it. So damned if I do, damned if I don’t.

I figured as much Bob. Unfortunately unlike in the physical world where old products eventually wear or rust or fade, when they’re digital this doesn’t occur and you just can’t continue updating and supporting old projects forever. Eventually you just have to pull the plug just to keep your workload manageable. Hopefully something will step up to fill the void. Cheers.

Well, I won’t say never, but we are one developer short right now and the consulting work is very good right currently. The top two priorities are ActiveRecord/ARGen and Shorts. Both of which we use on a daily basis so it’s important to keep them updated.

One developer short you say? :wink:

Yeah, we hired a developer in KC with Xojo ‘experience’. He wasn’t what we needed so we ended up letting him go after a disastrous client project. We prefer KC area folks simply because it creates better bonding experiences. Not that it couldn’t change with the right individual.

Arbed comes with a bunch of scripts, this one gets you some basic stats, though not everything you’re looking for:

Statistics.arbs

To use it, first open your project in Arbed, then double-click the script (which opens it in Arbed) and then Run it, applying it to the frontmost project.

Once you have a script open, click the Script Help button to open the Arbed Scripting web page, there’s a LOT it can do.

I Understand having someone local is nice since you can look over the table at them and say “what the hell are you thinking?” but I would open it up to a wider pool so you can get the right developer. Just my 2 cents. and I am overcharging you for my thoughts.

I’ve already given bob my thoughts
They paid me in consumable liquids :stuck_out_tongue:

And this thread has been totally hijacked. :slight_smile:

Well lets say “you know how I feel about local vs remote” :stuck_out_tongue:

I know, I know. Like I said, for the right individual it might be an option.

to kind of get the thread back on track kloc by itself is not a useful measure
defects per kloc is more useful
defects per commit is probably most useful