Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Source Code Line Count???

Status
Not open for further replies.

NeilFrank

Programmer
Mar 12, 2000
167
CA
Is there any way, other than summing the line counts, of ascertaining the total number of lines of executable code in a large multi- modular VB6 program I have written?
 
One option is to install the mztools suite of utilities into the IDE. These tools provide a lot of features, one of which happens to line count statistics.


That being said, the question I always ask when the issue of lines of source code comes up, why? What does it mean? What exactly are you measuring?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You could also create a new Add-In
Project, set a reference variable to VBIDE.VBE,
then cycle the CodeModules in the CodePanes collection,
and sum up the CountOfLines property.

Public VBRefVAr As VBIDE.VBE

Dim n As Integer
Dim m As Integer

For n = VBRefVar.CodePanes.Count To 1 Step -1
m = m + VBRefVar.CodePanes(n).CodeModule.CountOfLines
Next n

MsgBox m & " Lines of code."
 
Yes, but the mztools brings so much more than only line counting. It's actually a "must have"....


Greetings,
Rick
 
Ain't that true. If you don't have it, get it! I just wanted
to show how it can be done easily...
 
and what are the necessities in mztools?




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
I'm not sure I understand your question MichaelRed. I guess there are no necessities in mztools, but there are many tools and nice to have features.

I"m still waiting on what the value of the Source Line Count actually is?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
O.K. then a derived question.

Just substtute 'features' for 'necessities' in my previous post / question.

I also have never quite beleived in using the source code line count for much. WAY back when ... many structured programming discussions included some guidelines re the size of a procedure and 'reasonable' expectations on the ERROR FREE code expected from a programmer over time. Coincidentally, some of the guru's used the same number 50 lines of code in a procedure, and 50 lines of ERROR FREE code per day), so a 'programmer' could be expected to produce on small procedure per day of error free code.

Since "way back when ..." I have heard discussions re the subject in every concieveable aspect / dimension:

Is this the average programmer?

Does this include blank and or comment lines?

Should/does the 'errror free' criteria mean that the production code / procedure necessarily include a test / demo of the procedure - and if so is this part of the line count?

Does 'error free' mean / imply adequate comments and/or formal documentation?

Does (or should) the line count vary with language (e.g. should c programmers produce more / fewer lines than C++ or VB of COBAL or FORTRAN or ... programmers)?

Could one make an argument re their 'value' (pay rate?) based on their production aginst such a goal/benchmark?

...

and an infinite number of variations on JUST these items ...





MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Exactly my point MichaelRed, there are so many interpretations that its hard to understand just what you're after by counting lines of source code.

Consider the following example:
Code:
If A<B And C<D And E<F And G<H and I<J Then
   i = i + 1
End If
How many lines of executable code?

Now this example:
Code:
If A < B Then
   If C < D Then
      If E < F Then
         If G < H Then
            If I < J Then
               i = i + 1
            End If
         End If
      End If
   End If
End If
How many lines of executable code?

Given that these are logically equivalent, they may not be executably equivalent. Depending on the code generated by the compiler of course, It may be that in the first case, each comparison is checked and all of the boolean operations applied to determine whether we need to increment i. In the second case, the comparisons are done only 1 at a time, and as soon as a failure occurs, we exit the the conditional statements. And we're not performing any of the boolean operations.

So I now ask, which code is better? The 3 line compound conditional, or the 11 line cascading conditional?


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I remember reading a story in Sharktank ( computerworld.com ) about a guy that wrote some code and was working against a competing group writing code for the same purpose. His code was x number of lines, of which half were comments.

The other teams code had many less lines, but had 0 lines of comments.

His code actually ran faster, but the other team's code was chosen because it had fewer lines.

Robert
 
... which still left with the question ... re mztools...

not to mention a response from NeilFrank iulluminating the use/need/desire for the arcania????




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Maybe he gets paid by lines of code :)
That would be nice...
 
Counting lines seems to me to simple to even try.
I've tried to use the statistics ProjectAnalyzer gives:

In their own words: &quot;Estimate the quality of your code with metrics such as logical lines of code, cyclomatic complexity, depth of conditional nesting, comment to code ratio, length of names etc.&quot;

Bottom line (in my opinion): if you have no information at all about a huge amount of code, this might help to find the overly complex bits.
Much faster is just to go to the coffeemachine, wait for the guy who wrote the code, and ask what he thought was the tricky part...
 
Paid by lines of code??

If _
A _
< _
B _
Then
i _
= _
i _
+ _
1
End If



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I'm more than a little amazed by this to-and-fro. Has Tek Tips gotten a lot chattier lately or have I been asking the wrong questions?

Well, I do have a lot of comments and there is some white space in my code (but not enough to drive a truck through). OTOH, I have lately become partial to clumping logically related statements on a single line using : spacers. (How are those counted?) And tight code comes after Julia Roberts and apple pie in my view. Maybe even before apple pie.

I'm not getting paid by the line (or at all FTM). So why did I ask? Well, begging the question being batted about here, it’s a reverse Wizard of Oz thing: potential users of my Ap may not realize how much crunching lies behind what they're seeing on the screen and I want them to know.

Many thanks for the suggestions, gurus, which I will certainly be trying. My guess is it will come out around 20,000.

(And if only there were so many responses to the other query I posted last night on the background color of a TreeView, he sighed wistfully)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top