This will becoming a never ending story.

In my opinion, documentation shall be done before writing the code.
When I'm not to lazy and I do documentation, I set it before the
subroutine definition. Usually, at a precise moment, I'm looking to
the documentation or to the code, hardly I need both at some time.

Note: 90% of the times, in this cases, I use shift and I don't create
the @data variable, I use the @_ directly. @_ has a clear meaning.

Best Regards
Marcos Rebelo

On Mon, Jun 28, 2010 at 6:12 PM, Randal L. Schwartz
<mer...@stonehenge.com> wrote:
>>>>>> "marcos" == marcos rebelo <ole...@gmail.com> writes:
>
> marcos> I think that I didn't opposed myself to the pattern:
> marcos> sub xpto {
> marcos>     my $var1 = shift;
> marcos>     my $var2 = shift;
> marcos>     ...
> marcos> }
>
> marcos> Where it is clear that you wont to assign the parameters. 90% of the
> marcos> times I prefer to have pattern
>
> marcos> sub xpto {
> marcos>     my ($var1, $var2) = @_;
> marcos>     ...
> marcos> }
>
> marcos> since, in my opinion, makes the intentions more clear.
>
> I prefer the first, because it makes it easy to write:
>
>  sub xpto {
>    my $self = shift;
>    my $options = shift; # HASH: options to modify behavior
>    my @data = @_; # remainder is values to make this work
>
> As in, the shifting-a-bit-at-a-time lets me do three things:
>
>  1) clearly have "my $self = shift" separate from everything else,
>  since that's the special sauce that makes Perl objects work
>
>  2) have a place to put a comment about the type and purpose of each
>  parameter. Sure you can do that inside a my ($x, $y, $z) list, but
>  comments inside a () always scares me a bit
>
>  3) easily add an array to capture the "remainder" of the input values,
>  if it's a "varargs" style function.
>
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>



-- 
Marcos Rebelo
http://oleber.freehostia.com
Milan Perl Mongers leader http://milan.pm.org
Webmaster of http://sites.google.com/site/oleberperlrecipes/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to