Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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 :)

Cheers,
Ovid

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


Comment on Re: Programs/Methods for analyzing an existing Perl based system
Select or Download Code
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; } } }


    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://170248]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-12-28 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls