Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

I need perl coding standards

by kprasanna_79 (Hermit)
on May 28, 2005 at 06:09 UTC ( #461289=perlquestion: print w/ replies, xml ) Need Help??
kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Greatings Monks,
I have to design some modules in my projects. I need the coding standards before that. I know the basic standards like
use strict; use warnings; pods comments for program etc..
But i need to know whether any specified man page for perl coding standards. I will be thankful if u can give any of that..
--Prasanna.k

Comment on I need perl coding standards
Download Code
Re: I need perl coding standards
by Zaxo (Archbishop) on May 28, 2005 at 06:13 UTC

    The perldocs perlstyle and perlmod should cover what you want.

    After Compline,
    Zaxo

Re: I need perl coding standards
by gaal (Parson) on May 28, 2005 at 06:25 UTC
    In addition to Zaxo's suggestions, take a look at perltrap and search the Monastery for additional discussions about gotchas. (I don't mean to give the impression that style should be informed only by gotchas; but some of them can systematically be avoided by a good style guide.)

    Then read Abigail's Coding Guidelines for Perl. With any style guide there will be things you disagree with; Abigail's is notable in that everything comes with a rationale you can learn from / argue against.

Re: I need perl coding standards
by dbwiz (Curate) on May 28, 2005 at 07:23 UTC

    There are no widespread standards, but you may find a few guidelines (as others have pointed out).

    A good one, IMO, is the Slash Style Guide. It is especially interesting because its aim is to standardize code contributed by different people.

      I found this bit odd:
      Do not use shift. Use @_. shift is slower, and Brian has an allergic reaction to it.
      my $var = shift; # wrong my($var) = @_; # right sub foo { uc $_[0] } # OK my($var1, $var2) = (shift, shift); # Um, no.
      I always use shift, and I recall benchmarking it way back in the day before I made that decision, just to make sure it wasn't slower. Here's the test I used, and the results:
      use Benchmark qw(cmpthese); sub x_shift { while(@_) { my $a = shift; } } sub x_copy1 { for(my $i = 0; $i < $#_; $i++) { my $a = $_[$i]; } } sub x_copy2 { my $end = $#_; for(my $i = 0; $i < $end; $i++) { my $a = $_[$i]; } } my @args = (1 .. 100); cmpthese(1000000, { x_shift => 'x_shift(@args)', x_copy1 => 'x_copy1(@args)', x_copy2 => 'x_copy2(@args)' });
      Rate x_copy2 x_copy1 x_shift x_copy2 609756/s -- -18% -45% x_copy1 746269/s 22% -- -32% x_shift 1098901/s 80% 47% --
      Seeing the flat claim that shift is slower made me rethink my earlier test and try something more simple:
      use Benchmark qw(cmpthese); sub x_shift { my $a = shift } sub x_copy { my $a = $_[0] } my @args = (1 .. 3); cmpthese(1000000, { x_shift => 'x_shift(@args)', x_copy => 'x_copy(@ar +gs)' });
      Sure enough, the results changed, but now it appears to be a tie:
      Rate x_copy x_shift x_copy 1298701/s -- -0% x_shift 1298701/s 0% --

      The results fluctuate a few percent in each direction. Anyway, my point is that I don't think performance is a reason to avoid using shift.

      (I have a whole directory of benchmarks for silly little things, e.g. benchmarking exists() vs. a test for truth on a hash key and crazy stuff like that. It's a disease...but it amuses me :-)

Re: I need perl coding standards
by Juerd (Abbot) on May 28, 2005 at 09:02 UTC
Re: I need perl coding standards
by eyepopslikeamosquito (Canon) on May 28, 2005 at 09:32 UTC
      I should note that my guide in that list is specifically and only intended for large scale Perl Object Oriented development.

      Many of it's points may be incorrect or not relevant for smaller projects, or projects that are not OO.
Re: I need perl coding standards
by TheDamian (Priest) on May 28, 2005 at 22:24 UTC
    In addition to the excellent free resources mentioned above, there will also soon be:
    Perl Best Practices, by Damian Conway, O'Reilly, August 2005, 550pp, ISBN: 0-59600-173-8
    which offers a comprehensive coding standard (256 guidelines).

    I'll leave it to my fellow monks, several of whom have helped me fine-tune the book, to tell you whether or not it will be worth waiting two months, and then paying good money, for. ;-)

Re: I need perl coding standards
by stefp (Vicar) on May 29, 2005 at 01:21 UTC
    Mandriva has an ocaml application to enforce Perl coding standard. So this means they have coding standard to begin with. They use Perl for many of their installation and administration procedures and their code is of good quality. BTW, one of their perl programmer is Rafael Garcia Suarez, a perl pumpking.

    This application is called perl_checker and is part of the perl-MDK-Common rpm.

    -- stefp

Re: I need perl coding standards
by planetscape (Canon) on Jun 20, 2005 at 18:16 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://461289]
Approved by mrborisguy
Front-paged by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-08-27 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls