Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Lines of code
Message
From
26/09/2002 09:17:14
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Lines of code
Miscellaneous
Thread ID:
00704650
Message ID:
00704650
Views:
74
I have seen statements that such-and-such a program had so-and-so many lines of code. How would such a thing be calculated in an IDE like VFP, where a great part of the development is done with the property sheet, or moving objects around with the mouse?

Of course, I am aware that any definition of how many lines a specific form has is arbitrary, but I would still appreciate any ideas on how this might be handled.

One possibility is to convert the form to text with the class browser. Another is to use scctext.

For reports and menus, the class browser can't generate code, so I use scctext. The results are terribly inflated - that is, a large amount of lines for a relatively simple report.

For anybody interested, here is my current code to count lines. I thought about publishing it in the FAQ section, but I wanted some ideas on the points mentioned above, first.
* Create statistics (line count) for project
* By Hilmar Zonneveld

* Because of the commands used - especially project properties - this program
* requires VFP 6 or later.

* Execution can take a long time for a large project.

* Disclaimer: I consider any intent to count the number of lines in a project as prone to
* differences in opinion, inaccuracies, or even manipulation.
* For instance:
*   Should comments and blank lines be included in the line-count, or not?
*     A well-placed comment can be as important as a line of "real" code!
*   What to do about development that is basically not stored in a text-file -
*     like a form or report where you work mainly with properties,
*     in the property sheet?
*   An inefficient project, with lots of duplicate code, where inheritance or function
*     calls should have been used, will give an impressive line-count.

clear all
if type("Application.ActiveProject") # "O"
	MessageBox("Please open the project you want to analyze.")
	return
endif
create Table TmpLines (FileName C(30), Type C(1), LineCount I, Contents M)
do (_browser)
local lcTextFile, lnLineCount, lcFileContents, lnFileCount
lnFileCount = 0
FOR EACH oFile IN Application.ActiveProject.Files
	if oFile.Type $ "PKBVMRB"
		lnFileCount = lnFileCount + 1
		wait window nowait "Processing File #" + trans(lnFileCount) + chr(13) + chr(10);
			+ oFile.Name
		do case
		case oFile.Type = "P"
			lcTextFile = oFile.Name
		case oFile.Type $ "KBV"
			_oBrowser.AddFile(oFile.Name)
			_oBrowser.ExportClass(.F., "temp.txt")
			lcTextFile = "temp.txt"
			_oBrowser.RemoveClass()
		case oFile.Type $ "MRB"
			* Because of the method used, line count is terribly inflated
			* for menus, reports and labels (see output in memo field)
			do (_sccText) with oFile.Name, oFile.Type, "temp.txt", .T.
			lcTextFile = "temp.txt"
		endcase
		lcFileContents = FileToStr(lcTextFile)
		lnLineCount = occurs(chr(13), lcFileContents)
		insert into TmpLines (FileName, Type, LineCount, Contents);
			values (justfname(oFile.Name), oFile.Type, lnLineCount, lcFileContents)
	endif
ENDFOR

*!*	Codes for file-types:
*!*	d	Database
*!*	D	Free Table
*!*	Q	Query
*!*	K	Form
*!*	R	Report
*!*	B	Label
*!*	V	Visual Class Library
*!*	P	Program
*!*	L	FLL
*!*	Z	APP
*!*	M	Menu
*!*	T	Text
*!*	x	Other
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Next
Reply
Map
View

Click here to load this message in the networking platform