mikfire has asked for the wisdom of the Perl Monks concerning the following question:

Yes, I know most measures like this are severely broken. Basically, I have an old set of perl code ( evolved from perl4 over the course of several years ) and I am trying to rewrite it. My boss is all over my back becuase it is, he thinks, taking too long. I am looking for a tool ( other than, say, wc -l ) to measure the complexity of the old code and explain to him, in a way his lobotimized^w manager's brain can understand, that the task is very complex and it might actually take me a few months. Has anybody found/built anything to do this for perl code? Even something primitive, like measuring KLOC, the number of branches, the number of loops, etc. If I had time, I am sure I could hack some abomination together, but I just plain don't have it. TIA, Mik
  • Comment on Is there a way to measure code complexity?

Replies are listed 'Best First'.
Re: Is there a way to measure code complexity?
by dlc (Acolyte) on Feb 08, 2000 at 15:58 UTC
Re: Is there a way to measure code complexity?
by agoth (Chaplain) on Feb 08, 2000 at 16:06 UTC
    Have a look at Devel::Coverage as well, may help to give you an idea about whats going on
RE: Is there a way to measure code complexity?
by Anonymous Monk on Feb 09, 2000 at 00:13 UTC
    SnIff++ also purports to present code of any complexity with a friendly, well-labeled interface, and their demo may suffice for purposes of demonstration. It also draws block diagrams where you would not, I think. Visio will too, but it also sucks lymph out of users, and is about the least-free software anywhere. In a pinch, you can simply run lharc5 on the old code and see whether it what its compression ratio is compared to Management Sample Code's. Hence, for 40k blocks of code, 200:1 : 500:1 or 2:5, your code is e^((5/2)-1) times as complex. If you compile using ActiveState's tools, you can just compare binary file sizes! :) Actual complexity needs to be defined in your favorite flavor of formal method! No prototype, no metrics!
Re: Is there a way to measure code complexity?
by stephen (Priest) on Feb 09, 2000 at 04:55 UTC
    If you haven't already, get the Refactoring book by (I think) Martin Fowler. It's an extremely valuable book about upgrading code in-place, and also contains a segment on discussing code improvement with management. Frankly, if your boss doesn't understand that quality coding takes time, deception might be necessary to communicate effectively with him.
Re: Is there a way to measure code complexity?
by pschoonveld (Pilgrim) on Feb 10, 2000 at 00:37 UTC
    I think there is a way you could execute a program and report the CPU time it requires, which could translate into instructions. The number of instructions would be something I would tell my boss about. Seems to me that there is a command line *nix tool for this.
RE: Is there a way to measure code complexity?
by nickcave25 (Acolyte) on Feb 08, 2000 at 15:57 UTC
    what does wc -l do? what is KLOC? what is TIA?
      > what does wc -l do? wc is a Unix/Linux word count program. By default, it prints the number of bytes, words, and lines in a file. The "-l" option tells it to print only the number of lines. It is a quick way to measure lines of code. > what is KLOC? KLOC is a measurement of lines of code. 1 KLOC = 1000 lines of code (one kilo-LOC). 2 KLOC = 2000 lines of code, etc. > what is TIA? TIA = Thanks In Advance.