From: Eric Sunshine <sunshine@sunshineco.com>
To: "Célestin Matte" <celestin.matte@ensimag.fr>
Cc: Git List <git@vger.kernel.org>,
benoit.person@ensimag.fr,
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Subject: Re: [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style
Date: Sun, 9 Jun 2013 20:50:40 -0400 [thread overview]
Message-ID: <CAPig+cQWQ842-ZG3_JQxZ=-2qLPpijx9z3vtXns+G3xxp6PsyQ@mail.gmail.com> (raw)
In-Reply-To: <1370816573-3808-23-git-send-email-celestin.matte@ensimag.fr>
On Sun, Jun 9, 2013 at 6:22 PM, Célestin Matte
<celestin.matte@ensimag.fr> wrote:
> - strings which don't need interpolation are single-quoted for more clarity and
> slight gain of performance
> - interpolation is preferred over concatenation in many cases, for more clarity
> - variables are always used with the ${} operator inside strings
> - strings including double-quotes are written with qq() so that the quotes do
> not have to be escaped
> ---
> diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
> index a66cef4..efc376a 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki.perl
> +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
> @@ -200,10 +200,10 @@ sub mw_connect_maybe {
> lgdomain => $wiki_domain};
> if ($mediawiki->login($request)) {
> Git::credential \%credential, 'approve';
> - print STDERR "Logged in mediawiki user \"$credential{username}\".\n";
> + print STDERR qq(Logged in mediawiki user "$credential{username}".\n);
Given this patch's intention to use ${} within strings, should this be
${credential{username}}?
(I don't have a preference, but it's a genuine question since it's not
clear if this was an oversight or intentional.)
> } else {
> - print STDERR "Failed to log in mediawiki user \"$credential{username}\" on $url\n";
> - print STDERR " (error " .
> + print STDERR qq(Failed to log in mediawiki user "$credential{username}" on ${url}\n);
Ditto: ${credential{username}}
> + print STDERR ' (error ' .
> $mediawiki->{error}->{code} . ': ' .
> $mediawiki->{error}->{details} . ")\n";
> Git::credential \%credential, 'reject';
> @@ -347,10 +347,10 @@ sub get_mw_pages {
> # $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
> sub run_git {
> my $args = shift;
> - my $encoding = (shift || "encoding(UTF-8)");
> - open(my $git, "-|:$encoding", "git " . $args)
> - or die "Unable to open: $!\n";
> - my $res = do {
> + my $encoding = (shift || 'encoding(UTF-8)');
> + open(my $git, "-|:${encoding}", "git ${args}")
> + or die "Unable to fork: $!\n";
> + my $res = do {
The whitespace-only change to line "my $res = do {" is effectively
noise. The reviewer has to stop and puzzle out what changed on the
line before continuing with review of the remaining _real_ changes. It
is a good idea to avoid noise changes if possible.
In this particular case, it's easy to avoid the noise since the
trailing space on that line could/should have been removed in patch
18/28 when the statement was split over multiple lines.
> local $/ = undef;
> <$git>
> };
> @@ -475,26 +475,26 @@ sub download_mw_mediafile {
> return $response->decoded_content;
> } else {
> print STDERR "Error downloading mediafile from :\n";
> - print STDERR "URL: $download_url\n";
> - print STDERR "Server response: " . $response->code . " " . $response->message . "\n";
> + print STDERR "URL: ${download_url}\n";
> + print STDERR 'Server response: ' . $response->code . q{ } . $response->message . "\n";
To meet the goals of this patch, would you want to do this instead?
"Server response: @{[$response->code]} @{[$response->message]}\n";
Whether this is easier or more difficult to read is a matter of
opinion. (Again, this is a genuine question rather than a show of
preference on my part.)
> exit 1;
> }
> }
> @@ -691,8 +691,7 @@ sub fetch_mw_revisions {
> my $n = 1;
> foreach my $page (@pages) {
> my $id = $page->{pageid};
> -
> - print STDERR "page $n/", scalar(@pages), ": ". $page->{title} ."\n";
> + print STDERR "page ${n}/", scalar(@pages), ': ', $page->{title}, "\n";
Similarly:
"page ${n}/@{[scalar(@pages)]}: @{[$page->{title}]}\n"
> $n++;
> my @page_revs = fetch_mw_revisions_for_page($page, $id, $fetch_from);
> @revisions = (@page_revs, @revisions);
> @@ -706,7 +705,7 @@ sub fe_escape_path {
> }
> - print STDOUT "N inline :$n\n";
> - literal_data("mediawiki_revision: " . $commit{mw_revision});
> + print STDOUT "N inline :${n}\n";
> + literal_data("mediawiki_revision: $commit{mw_revision}");
As questioned earlier, do you want ${commit{mw_revision}}?
> print STDOUT "\n\n";
> return;
> }
> @@ -911,8 +910,8 @@ sub mw_import_revids {
> my $page_title = $result_page->{title};
>
> if (!exists($pages->{$page_title})) {
> - print STDERR "$n/", scalar(@$revision_ids),
> - ": Skipping revision #$rev->{revid} of $page_title\n";
> + print STDERR "${n}/", scalar(@$revision_ids),
> + ": Skipping revision #$rev->{revid} of ${page_title}\n";
Same question as above regarding formatting via "@{[...]}".
> next;
> }
>
> @@ -937,14 +936,14 @@ sub mw_import_revids {
> # If this is a revision of the media page for new version
> # of a file do one common commit for both file and media page.
> # Else do commit only for that page.
> - print STDERR "$n/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
> + print STDERR "${n}/", scalar(@$revision_ids), ": Revision #$rev->{revid} of $commit{title}\n";
Ditto.
> import_file_revision(\%commit, ($fetch_from == 1), $n_actual, \%mediafile);
> }
next prev parent reply other threads:[~2013-06-10 0:50 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-09 22:22 [PATCH v3 00/28] Follow perlcritic's recommandations Célestin Matte
2013-06-09 22:22 ` [PATCH v3 01/28] git-remote-mediawiki: Make a regexp clearer Célestin Matte
2013-06-09 22:22 ` [PATCH v3 02/28] git-remote-mediawiki: Move "use warnings;" before any instruction Célestin Matte
2013-06-09 22:22 ` [PATCH v3 03/28] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8) Célestin Matte
2013-06-09 22:22 ` [PATCH v3 04/28] git-remote-mediawiki: Always end a subroutine with a return Célestin Matte
2013-06-09 22:22 ` [PATCH v3 05/28] git-remote-mediawiki: Move a variable declaration at the top of the code Célestin Matte
2013-06-09 22:22 ` [PATCH v3 06/28] git-remote-mediawiki: Change syntax of map calls Célestin Matte
2013-06-09 22:22 ` [PATCH v3 07/28] git-remote-mediawiki: Rewrite unclear line of instructions Célestin Matte
2013-06-11 15:04 ` Junio C Hamano
2013-06-11 16:35 ` Matthieu Moy
2013-06-11 18:09 ` Junio C Hamano
2013-06-11 20:13 ` Célestin Matte
2013-06-11 21:55 ` Junio C Hamano
2013-06-09 22:22 ` [PATCH v3 08/28] git-remote-mediawiki: Remove useless regexp modifier (m) Célestin Matte
2013-06-09 22:22 ` [PATCH v3 09/28] git-remote-mediawiki: Change the behaviour of a split Célestin Matte
2013-06-10 8:29 ` Matthieu Moy
2013-06-09 22:22 ` [PATCH v3 10/28] git-remote-mediawiki: Change separator of some regexps Célestin Matte
2013-06-09 22:22 ` [PATCH v3 11/28] git-remote-mediawiki: Change style in a regexp Célestin Matte
2013-06-09 22:22 ` [PATCH v3 12/28] " Célestin Matte
2013-06-09 22:22 ` [PATCH v3 13/28] git-remote-mediawiki: Add newline in the end of die() error messages Célestin Matte
2013-06-09 22:22 ` [PATCH v3 14/28] git-remote-mediawiki: Change the name of a variable Célestin Matte
2013-06-09 22:22 ` [PATCH v3 15/28] git-remote-mediawiki: Turn double-negated expressions into simple expressions Célestin Matte
2013-06-09 22:22 ` [PATCH v3 16/28] git-remote-mediawiki: Remove unused variable $entry Célestin Matte
2013-06-09 22:22 ` [PATCH v3 17/28] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword Célestin Matte
2013-06-09 22:22 ` [PATCH v3 18/28] git-remote-mediawiki: Assign a variable as undef and make proper indentation Célestin Matte
2013-06-09 22:22 ` [PATCH v3 19/28] git-remote-mediawiki: Check return value of open Célestin Matte
2013-06-09 22:22 ` [PATCH v3 20/28] git-remote-mediawiki: remove import of unused open2 Célestin Matte
2013-06-09 22:22 ` [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine Célestin Matte
2013-06-11 15:42 ` Junio C Hamano
2013-06-11 22:24 ` Célestin Matte
2013-06-09 22:22 ` [PATCH v3 22/28] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
2013-06-10 0:50 ` Eric Sunshine [this message]
2013-06-10 10:48 ` Célestin Matte
2013-06-10 8:37 ` Matthieu Moy
2013-06-10 11:00 ` Célestin Matte
2013-06-10 16:41 ` Junio C Hamano
2013-06-10 17:18 ` Benoît Person
2013-06-10 17:30 ` Matthieu Moy
2013-06-10 19:01 ` Junio C Hamano
2013-06-09 22:22 ` [PATCH v3 23/28] git-remote-mediawiki: Brace file handles for print for more clarity Célestin Matte
2013-06-09 22:22 ` [PATCH v3 24/28] git-remote-mediawiki: Replace "unless" statements with negated "if" statements Célestin Matte
2013-06-09 22:22 ` [PATCH v3 25/28] git-remote-mediawiki: Don't use quotes for empty strings Célestin Matte
2013-06-09 22:22 ` [PATCH v3 26/28] git-remote-mediawiki: Put non-trivial numeric values in constants Célestin Matte
2013-06-09 22:22 ` [PATCH v3 27/28] git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki") Célestin Matte
2013-06-09 22:22 ` [PATCH v3 28/28] git-remote-mediawiki: Clearly rewrite double dereference Célestin Matte
2013-06-10 1:09 ` [PATCH v3 00/28] Follow perlcritic's recommandations Eric Sunshine
2013-06-10 8:46 ` Matthieu Moy
2013-06-11 12:54 ` Célestin Matte
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPig+cQWQ842-ZG3_JQxZ=-2qLPpijx9z3vtXns+G3xxp6PsyQ@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=benoit.person@ensimag.fr \
--cc=celestin.matte@ensimag.fr \
--cc=git@vger.kernel.org \
--cc=matthieu.moy@grenoble-inp.fr \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).