From: Junio C Hamano <junkio@cox•net>
To: merlyn@stonehenge•com (Randal L. Schwartz)
Cc: Jakub Narebski <jnareb@gmail•com>, git@vger•kernel.org
Subject: Re: [PATCH] gitweb: Make git_get_refs_list do work of git_get_references
Date: Sat, 16 Sep 2006 19:12:27 -0700 [thread overview]
Message-ID: <7vejub8cms.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <864pv7tgmx.fsf@blue.stonehenge.com> (Randal L. Schwartz's message of "16 Sep 2006 18:40:22 -0700")
merlyn@stonehenge•com (Randal L. Schwartz) writes:
>>>>>> "Junio" == Junio C Hamano <junkio@cox•net> writes:
>
> Junio> Jakub Narebski <jnareb@gmail•com> writes:
>>> Make git_get_refs_list do also work of git_get_references, to avoid
>>> calling git-peek-remote twice. It now returns either list of refs as
>>> before in scalar context, or references hash and list of refs in list
>>> context.
>
> Junio> I do not think we want to have too many functions that return
> Junio> different things depending on contexts. Forcing callers to
> Junio> remember what the function does in which context is bad.
>
> That's even an inaccurate description, so an expert in Perl (I've
> known a few) would just scratch his head.
>
> You cannot ever ever return a list in a scalar context. Ever. Never ever.
That much I think I know.
The code I was complaining about tries to do something like
this:
sub that_sub {
...
return wantarray ? (\@bar, \%foo) : \@bar;
}
and it is not done for optimization purposes (i.e. "if the
caller only wants one and we are returning \@bar then we do not
have to compute \%foo which is a big win" is not why it does
this wantarray business).
So the callers when interested in the sequence of things in 'bar'
typically say:
my $the_list = that_sub(...);
for (@$the_list) {
...
}
while other callers say:
my ($the_hash, $the_list) = that_sub(...);
... use %$the_hash and @$the_list as see fit ...
And I was saying that getting rid of the "return wantwarray ? :"
business and write the first class of callers like this
my ($the_list) = that_sub(...);
for (@$the_list) {
...
}
would be much less confusing.
next prev parent reply other threads:[~2006-09-17 2:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-17 0:26 [PATCH] gitweb: Make git_get_refs_list do work of git_get_references Jakub Narebski
2006-09-17 0:37 ` [PATCH 1/2] gitweb: Always use git-peek-remote in git_get_references Jakub Narebski
2006-09-17 1:22 ` [PATCH] gitweb: Make git_get_refs_list do work of git_get_references Junio C Hamano
2006-09-17 1:40 ` Randal L. Schwartz
2006-09-17 2:12 ` Junio C Hamano [this message]
2006-09-17 2:17 ` Randal L. Schwartz
2006-09-17 2:29 ` Junio C Hamano
[not found] ` <200609171057.56467.jnareb@gmail.com>
[not found] ` <7vfyeq6dn3.fsf@assigned-by-dhcp.cox.net>
2006-09-17 10:00 ` [PATCH 2/2 (take 2)] " Jakub Narebski
2006-09-17 10:02 ` Jakub Narebski
2006-09-17 10:06 ` Jakub Narebski
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=7vejub8cms.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox$(echo .)net \
--cc=git@vger$(echo .)kernel.org \
--cc=jnareb@gmail$(echo .)com \
--cc=merlyn@stonehenge$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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