On Fri, 2 Nov 2001, Stephen Adkins wrote:

> At 09:54 PM 11/2/2001 +0200, Robin Berjon wrote:
> >On Friday 02 November 2001 20:14, Stephen Adkins wrote:
> >> I have grabbed the Slash style guide, removed/modified
> >> the offending sections (exit/die, DESTROY, shift), and
> >> created a proposed P5EE style guide.
> >
> >It seems that you forgot shift. Please remove it, or even better, incite
> >people to use it except when there is a really good reason not to (eg silly
> >accessors sub getFoo { return $_[0]->[FOO]; } ).
>
> Can you explain what you would change in this section?
>
> =head2 shift
>
> Where possible, use @_ rather than shift.  shift is slower.
>
>     my $var = shift;                     # wrong
>     my ($var) = @_;                      # right
>     my ($var1, $var2, $var3) = @_;       # right
>     sub foo { uc $_[0] }                 # OK
>     my ($var1, $var2) = (shift, shift);  # Um, no.
>
> However, where you will be passing the parameters to another method,
> a shift is sometimes appropriate.
>
>     sub method1 {
>         my $self = shift;
>         $self->method2(@_);
>     }

Personaly this whole section stinks. People use different methods, but for
me, I try and avoid direct @_ access unless absolutely necessary. For
method calls I prefer:

  my $self = shift;
  my ($param1, $param2) = @_;

or alternatively:

  my $self = shift;
  my %params = @_; # I like key/value pairs.

For functions it's the same but without the $self line.

I also like to validate params if I'm being uber-strict. Which I don't
tend to be for CPAN modules, but I do for work-oriented modules. I tend to
use a derivative of some of D.Rolsky's code that he wrote while we were
working together (Dave's good at that sort of thing, being as anal as he
is :-)

> >Something that needs to be discussed imho is whether we have constants
> >defined with my $CONSTANT = 50 or with use constant CONSTANT => 50. Both
> have
> >pros and cons, and I never really could make up my mind here.
>
> .... or even
>
>    sub CONSTANT { 50; }

That's not compiled as a constant - you forgot the empty prototype.

> Methods and Functions beginning with C<_> are special:
> they are not to be used
> outside the current file (i.e. "private").
> This is not enforced by the code itself,
> but by programmer convention only.

I'd go with _method being protected and __method being private.

-- 
<Matt/>

    /||    ** Founder and CTO  **  **   http://axkit.com/     **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // ** mod_perl news and resources: http://take23.org  **
     \\//
     //\\
    //  \\

Reply via email to