git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gitweb: Refactor git_header_html
Date: Wed, 22 Jun 2011 08:44:34 +0200	[thread overview]
Message-ID: <201106220844.35431.jnareb@gmail.com> (raw)
In-Reply-To: <7v4o3i7nkt.fsf@alter.siamese.dyndns.org>

On Wed, 22 Jun 2011, Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
> 
> > P.S. I wonder if print_search_form() should also get passed %opts as
> > one of its parameters...
> 
> I do not particularly care for this:
> 
> 	sub foo {
>         	my %opts = @_;
> 
> 		if ($opts{-option} eq 'bar') {
>                 	... do this ...
> 
> style, which lets a caller pass any random typo to the callee, like so:
> 
> 	foo(-optoin => 'value');
> 
> But maybe it is just me.

Well, originally this style was used mainly to pass some extra rarely
set boolean flags; isn't

        foo($bar, "baz", -quux => 1, -corge => 1);

better than

        foo($bar, "baz", 1, 0, 1);

when it is ordinarily (most times) called as

        foo($bar, "baz");


When writing in C, one would probably use #defines for this:

        foo(bar, "baz", FOO_QUUX | FOO_CORGE);

but it is not very Perl-ish, I would think.

> > +sub print_header_links {
> > +	my %opts = @_;
> > +
> > +	# print out each stylesheet that exist, providing backwards capability
> > +	# for those people who defined $stylesheet in a config file
> > +	if (defined $stylesheet) {
> > +		print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
> > +	} else {
> > +		foreach my $stylesheet (@stylesheets) {
> > +			next unless $stylesheet;
> > +			print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
> > +		}
> > +	}
> > +	if ($opts{'-feed'}) {
> > +		print_feed_meta();
> > +	}
> 
> Here, we refrain from showing the <link> elements that are related to the
> RSS/Atom feeds (if we know what $project we are talking about), or <link>
> elements that are related to the project list (html top page and opml) if
> we are not showing a normal return, as $opts{'-feed'} is true only when we
> are returning '200 OK'.
> 
> The original implementation, even though it used statement modifiers after
> this print_feed_meta(), was much easier to follow, at least for me. The
> association between "feed-meta" and "200 OK" was close together and more
> direct.

Hmmm... perhaps then I should have gone with my first thought, namely
passing $status to print_header_links().  

Will resend.


Note that in case of print_nav_breadcrumbs() the code used %opts
originally, so it is only passed from git_header_html...

> > ...
> > -		}
> > -	}
> > -	print_feed_meta()
> > -		if ($status eq '200 OK');
> 
> Other than that, this looks a correct no-op patch that makes the resulting
> smaller functions easier to grok.

Thanks. 

-- 
Jakub Narebski
Poland

  reply	other threads:[~2011-06-22  6:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21 18:38 [PATCH] gitweb: Refactor git_header_html Jakub Narebski
2011-06-21 23:48 ` Junio C Hamano
2011-06-22  6:44   ` Jakub Narebski [this message]
2011-06-22 11:50     ` [PATCHv2] " 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=201106220844.35431.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).