git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junio@pobox.com>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gitweb: Uniquify usage of subroutine prototypes
Date: Tue, 25 Mar 2008 12:47:34 -0700	[thread overview]
Message-ID: <7vlk46lh61.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: Junio C. Hamano's message of "(unknown date)"

Junio C Hamano <gitster@pobox.com> writes:

> Jakub Narebski <jnareb@gmail.com> writes:
>
>> The idea is NOT to use subroutine prototypes to create new syntax;
>> prototypes are to be purely informational and optional.

That's unfortunately a grave misconception, isn't it?

For example, can you explain (1) how these three calls behave before
running them, and (2) why these three behave the way they do?

        sub foo       { my ($s, %f) = @_; print "s = $s\n"; }
        sub bar ($;%) { my ($s, %f) = @_; print "s = $s\n"; }

        my @it = ('This is my string');
        my %hash = (rose => 'blue', violet => 'green');

        foo @it, %hash;		# call 1
        bar @it, %hash;		# call 2
	bar $it[0], %hash;	# call 3

By adding ($;%) to an existing function that did not have prototype, you
changed the semantics of the function and:

 (1) it is your responsibility to make sure you did not break existing
     callers when you made such a change, and

 (2) programmers who want to call any existing function in your program
     need to check how the function groks its parameters and make sure
     they do not fall into the same pitfalls as the call sites you had to
     fix in step (1).  They cannot rely on the old fashioned "arguments
     are passed as a flattened list" idiom anymore before checking if you
     have prototypes to the function they want to call.

Prototypes used carelessly tend to force users to do unnecessary things,
because the caller cannot rely on the old fashioned "arguments are passed
as a flattened list" semantics and check how each and every function is
prototyped before making a call.

I am not saying that Perl prototypes is a bad thing.  The point of the
prototype is to change the syntax and semantics so that you can write a
function to which arguments are _not_ passed as a flattend list, and
without them you cannot write something that emulates "push @a, $b, $c".

But you need to be aware of what it does to your callers.

  reply	other threads:[~2008-03-25 19:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-25 12:11 [PATCH] gitweb: Uniquify usage of subroutine prototypes Jakub Narebski
2008-03-25 19:47 ` Junio C Hamano [this message]
2008-03-25 22:06   ` Rafael Garcia-Suarez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vlk46lh61.fsf@gitster.siamese.dyndns.org \
    --to=junio@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).