develooper Front page | perl.fwp | Postings from December 2007

Re: bad code to good golf

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
December 9, 2007 15:48
Subject:
Re: bad code to good golf
Message ID:
475C7EA9.4010504@pobox.com
A. Pagaltzis wrote:
> * Uri Guttman <uri@stemsystems.com> [2007-12-09 19:25]:
>> i don't like using shift for args if i can help it.
> 
> Personally I *always* use `shift` for the invocant, but
> assignment from `@_` for all other parameters in all but a few
> rare circumstances. So methods in my code always read something
> like this:
> 
>     sub frobnitz {
>         my $self = shift;
>         my ( $foo, $bar, $baz ) = @_;
>         # ...
>     }
> 
> It’s a nod to the fact that the invocant is not really in the
> same class (no pun intended) as the other parameters. Since
> `$self` is thus removed from `@_`, and is the *only* thing
> removed from it, that also makes it natural to write delegative
> code:
> 
>         # ...
>         $self->get_veeblefitzer()->frobnitz( @_ );
>         # ...

+1


-- 
...they shared one last kiss that left a bitter yet sweet taste in her
mouth--kind of like throwing up after eating a junior mint.
        -- Dishonorable Mention, 2005 Bulwer-Lytton Fiction Contest
           by Tami Farmer

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About