Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks

PerlMessy: Perltidy's little tattletaling sister

by jacques (Priest)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Jun 03, 2003 at 03:08 UTC ( #262550=sourcecode: print w/ replies, xml ) Need Help??

Category: Fun Stuff
Author/Contact Info jacques
Description: This small program rates a file's adherence to perltidy guidelines. You can easily modify it to meet your requirements. It was developed on a win32 platform with the standalone perltidy script.
#!perl.exe

#
#  Perl-Messy -a program that rates files adherence to perltidy guidli
+nes
#

die "usage: 'perlmessy file1 file2 file3 ...' or 'perlmessy *.pl'\n"
  unless $ARGV[0];

foreach (@ARGV) {

    @files = glob("$_");

    foreach (@files) {
  
       die "File $_ doesn't exist\n" unless (-e $_); 
         
        system("perl perltidy $_") == 0
          or die "pertidy produced an error";

        @lines = `diff -w $_ $_.tdy`;

        unlink("$_.tdy") or warn "File $_.tdy could not be deleted\n";

        $count = 0;

        foreach (@lines) {
            /^>|^</ and $count++;
        }

        if ( $count <= 4 ) {
            $message = "Larry Wall would be proud";
        }
        elsif ( $count <= 7 ) {
            $message = "Not too untidy";
        }
        elsif ( $count <= 12 ) {
            $message = "Might want to use perltidy";
        }
        elsif ( $count <= 17 ) {
            $message = "Do you like spagetti with your dinner?";
        }
        else {
            $message = "Enter an obsufication contest. You might win";
        }

        print "$_:\n $count deviations -- $message\n";

    }
}

Comment on PerlMessy: Perltidy's little tattletaling sister
Download Code
Re: PerlMessy: Perltidy's little tattletaling sister
by jmcnamara (Monsignor) on Jun 03, 2003 at 09:01 UTC

    Nice. ++

    I once planned to use perltidy to do something similar as part of CPANTS. However, it fell off the bottom of my TODO list. :-)

    One of the planned features was to compare the input and output sources using several known styles. This would hopefully give sufficient credit to code that was using a consistent style even if it didn't conform to perltidy's default which is perlstyle. The intention was to provide an objective code metric. Whether, the metric would be useful or not is another debate.

    One note, the system call should probably be something like the following for Unix systems:

    system("perltidy $_") == 0 ...

    --
    John.

[reply]
[d/l]
Re: PerlMessy: Perltidy's little tattletaling sister
by halley (Prior) on Jun 03, 2003 at 14:59 UTC

    Unfortunately, this only counts discrepancy in lines. It's a sort of Levenshtein Distance of lines.

    Typically, smart-indenting editors and perltidy can only approximate each other's code (since both are essentially trying to "parse" the syntax, and as we know, only perl can parse Perl). Emacs and perltidy can come close, but don't always agree. I tidy up some foreign code when I get it, then edit from there without re-tidying. So some level of disagreement is quite common.

    For a better result, I'd like to see a patch to perltidy where it accumulates a "cost to fix" for each situation it wants to fix. Then you're not post-processing perltidy, but asking perltidy itself: how bad was this sloppy code, quantitatively?

    I'd also like a minor mode in emacs where it occasionally executes (perl -c $filename) invisibly, then slightly tints the background of all the lines following the first error found (or better, though I think unsupported, is to tint the relevant fraction of the buffer's scrollbar). You could adjust this to do the same for perltidy... highlighting the first egregious tidy problem.

    --
    [ e d @ h a l l e y . c c ]

[reply]
[d/l]
[select]

Back to Code Catacombs

Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: sourcecode [id://262550]
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others wandering the Monastery: (8)
syphilis
bassplayer
atcroft
herveus
Eyck
broomduster
gnosti
raisputin
As of 2009-11-21 10:23 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (730 votes), past polls