Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Programs/Methods for analyzing an existing Perl based system

by Ovid (Cardinal)
on May 29, 2002 at 23:26 UTC ( #170248=note: print w/replies, xml ) Need Help??

in reply to Programs/Methods for analyzing an existing Perl based system

There is no real substitute for getting into the system and understanding how it works. Further, you have to know Perl fairly well, including good coding standards. I was recently helping a gentleman in the Netherlands with some Perl issues, when he emailed me a program and asked for feedback. Here's one of the subroutines:

sub stats { unless ($aantalja) { &pak_getallen; } $totaal_stemmen = ($aantalja + $aantalnee); $eenstem = (100 / $totaal_stemmen); $procentja = ($aantalja * $eenstem); $procentnee = ($aantalnee * $eenstem); $procentja = int($procentja); $procentnee = int($procentnee); if (($procentja + $procentnee) < 100) { if ($procentja > $procentnee) { $procentja+=1; } elsif ($procentja < $procentnee) { $procentnee+=1; } } }

Right off the bat, I can point to several problems. First, the subroutine is refers to variables declared outside of itself, so it's going to have side-effects that will be difficult to maintain. The indentation is poor, so it's tough to determine scope. Further, there's no sanity check to avoid a divide by zero error in this line:

$eenstem = (100 / $totaal_stemmen);

But does it work? Who knows? I don't speak Dutch. While there is plenty of information available in that little snippet, there is no meaning. Ultimately, this means that whatever metrics you want to produce, there is no substitute for understanding the code. Further, whatever metrics someone wants to put down as a standard, I guarantee that I can write code that will hit whatever target they are looking for, but still be an unmaintainable mess. Trust me, you should see some of my production code :)


Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Re: Programs/Methods for analyzing an existing Perl based system
by Beatnik (Parson) on May 29, 2002 at 23:47 UTC
    sub stats { unless ($numberyes) { &grab_numbers; } $total_votes = ($numberyes + $numberno); $onevote = (100 / $total_votes); $percentyes = ($numberyes * $onevote); $percentno = ($numberno * $onevote); $percentyes = int($percentyes); $percentno = int($percentno); if (($percentyes + $percentno) < 100) { if ($percentyes > $percentno) { $percentyes+=1; } elsif ($percentyes < $percentno) { $percentno+=1; } } }

    ... Quidquid perl dictum sit, altum viditur.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://170248]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-04-22 05:33 GMT
Find Nodes?
    Voting Booth?