Re: [PATCH 00/16] git-send-email cleanups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 30, 2010 at 14:30, Brian Gernhardt
<brian@xxxxxxxxxxxxxxxxxxxxx> wrote:

> None of these subroutines strictly need the prototype, but it does
> allow Perl to warn us if we send incorrect arguments. ÂWhy remove
> them? ÂAre they causing problems somewhere?

As Jeff pointed out prototypes are troublesome. If you want to be
warned about too many arguments a better way is:

    sub foo {
        warn sprintf "You gave me %d arguments", scalar @_ if @_ != 1;

Or something like that, but there's no reason to do that for these
subs in particular. There are 32 subroutines in git-send-email.perl,
these weren't in any way more special than the rest.

They probably had prototypes in the first place because they were
added by someone who was under the mistaken impression that Perl
prototypes were remotely similar to C-like prototypes, they're not.

The purpose of Perl prototypes is to rewrite the *caller* code, so
that e.g. if you have:

    sub blah ($$) { ... }

Perl will rewrite this call:

    blah @foo, @bar;

As:

    blah(scalar(@foo), scalar(@bar))

While a blah without prototypes would just be:

    blah(@foo, @bar);

Using prototypes superfluously like this makes it harder to read the
code, because you end up checking every call site for every subroutine
call that uses prototypes to see if rewriting the argument list like
this is producing some unexpected logic error.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]