From: Michael Witten <mfwitten@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Subject: Re: [PATCH RFC3.5 02/12] send-email: No longer repeatedly test if $smtp_server is a command
Date: Sun, 19 Apr 2009 23:53:16 -0500 [thread overview]
Message-ID: <49ec020a.050cc00a.2a50.ffffd0e3@mx.google.com> (raw)
In-Reply-To: <7viql0lzuw.fsf@gitster.siamese.dyndns.org>
On Sun, Apr 19, 2009 at 23:21, Junio C Hamano <gitster@pobox.com> wrote:
> Michael Witten <mfwitten@gmail.com> writes:
>
>> ...
>>> I think a genuine improvement would be something like:
>>>
>>> if (!defined $smtp_server) {
>>> $smtp_server = 'localhost';
>>> }
>>
>> You don't care to search for a possible sendmail?
>
> That's something you already did before setting smtp_server
> unconditionally to localhost, right? You do (in the above):
>
> if (user gave $smtp_server) {
> use it, notice and note if it is a command;
> } else {
> if (standard binary avaiable) {
> use it, note it is a command;
> }
> # otherwise it still is undef
> }
> if (!defined $smtp_server) {
> set it to localhost;
> }
>
> But I would probably write it this way:
>
> if (user didn't give us $smtp_server) {
> if (standard binary avaiable) {
> use it, note it is a command;
> } else {
> use localhost;
> }
> }
> if ($smtp_server looks like a command) {
> $smtp_server_is_a_command = true;
> }
>
>
I suppose it's hard to tell from the patch, but it's actually
a combination of those two:
if (user gave $smtp_server) {
use it, notice and note if it is a command;
} else { # use a default:
if (standard binary avaiable) {
use it, note it is a command;
} else {
use localhost;
# automatically noted as a command
# without doing anything (this would
# cause warnings if $smtp_is_a_command
# is used in places other than the bool
# context, because it will be undef);
# thus, my choice is a bad choice in
# the long run, but I'm sticking to it.
}
}
The actual code:
if (defined $smtp_server) {
$smtp_server_is_a_command = ($smtp_server =~ m{^/});
} else { # use a default:
foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {
if (-x $_) {
$smtp_server = $_;
$smtp_server_is_a_command = 1;
last;
}
}
$smtp_server = 'localhost' # 127.0.0.1 is not compatible with IPv6
unless $smtp_server_is_a_command;
}
(I'll remove the "127.0.0.1" comment).
There's a minimum of checking and assigning; it's beautiful.
Plus, this organization fits in well with the server/port
verification (if I recall).
P.S.
I also like:
$smtp_server_is_a_command or ($smtp_server = 'localhost');
or, maybe:
$smtp_server_is_a_command or $smtp_server = 'localhost;
However, I wasn't sure if that is acceptable to others; more
importantly (:-D), I'm not sure that perl is smart enough to
optimize away the unnecessary comparison of the values, so I
figured that the modifier 'unless' is morally superior, because
it probably has the advantage of fewer cycles than the 'or' form,
and it has greater readability than the curly-braced conditional.
I absolutely loathe curly braces around a body of one line:
if ($you_loath_this) {
print "Clap Your Hands!\n";
}
If only the curly-braces weren't there. I don't know why, they
just bug me terribly.
prev parent reply other threads:[~2009-04-20 5:06 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-18 17:01 [PATCH RFC3.5 00/12] Introduction to Decreasing send-email Entropy Michael Witten
2009-04-18 17:01 ` [PATCH RFC3.5 01/12] send-email: Cleanup the usage text and docs a bit Michael Witten
2009-04-18 17:01 ` [PATCH RFC3.5 02/12] send-email: No longer repeatedly test if $smtp_server is a command Michael Witten
2009-04-18 17:01 ` [PATCH RFC3.5 03/12] send-email: Interpret --smtp-server "" as "use a default" Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 04/12] send-email: Verification for --smtp-server and --smpt-server-port Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 05/12] send-email: Improve redability and error-handling in send_message's sendmail code Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 06/12] send-email: Cleanup and streamline the SMTP code in send_message Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 07/12] send-email: Cleanup send_message 'log' code Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 08/12] send-email: Move Subject sanitization from --compose code to send_message Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 09/12] Docs: send-email: Reorganize the CONFIGURATION section Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 10/12] Docs: Embolden the CONFIGURATION references Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 11/12] Docs: send-email: Clarification of sendemail.<identity> Michael Witten
2009-04-18 17:02 ` [PATCH RFC3.5 12/12] Docs: send-email: git send-email -> 'send-email' Michael Witten
2009-04-19 1:54 ` [PATCH RFC3.5 08/12] send-email: Move Subject sanitization from --compose code to send_message Jay Soffian
2009-04-19 2:37 ` Michael Witten
2009-04-19 14:13 ` Jay Soffian
2009-04-19 14:39 ` Michael Witten
2009-04-19 14:53 ` Michael Witten
2009-04-19 16:43 ` [PATCH RFC3.5.1 08/12] send-email: Simplify --compose subject sanitation Michael Witten
2009-04-21 2:34 ` Jeff King
2009-04-21 3:29 ` Michael Witten
2009-04-20 1:42 ` [PATCH RFC3.5 06/12] send-email: Cleanup and streamline the SMTP code in send_message Junio C Hamano
2009-04-20 5:38 ` Michael Witten
2009-04-20 6:43 ` Junio C Hamano
2009-04-19 1:51 ` [PATCH RFC3.5 05/12] send-email: Improve redability and error-handling in send_message's sendmail code Jay Soffian
2009-04-19 2:13 ` Michael Witten
2009-04-19 2:17 ` Thomas Adam
2009-04-19 2:43 ` Michael Witten
2009-04-19 4:44 ` Junio C Hamano
2009-04-19 13:49 ` [PATCH RFC3.5.1 05/12] send-email: Improve readability " Michael Witten
2009-04-19 14:16 ` [PATCH RFC3.5 05/12] send-email: Improve redability " Jay Soffian
2009-04-20 1:38 ` Junio C Hamano
2009-04-20 1:58 ` Junio C Hamano
2009-04-21 2:00 ` Jeff King
2009-04-21 3:14 ` Jeff King
2009-04-19 14:19 ` [PATCH RFC3.5.1 04/12] send-email: Verification for --smtp-server and --smpt-server-port Michael Witten
2009-04-20 15:53 ` Michael Witten
2009-04-20 1:42 ` [PATCH RFC3.5 " Junio C Hamano
2009-04-20 2:38 ` Junio C Hamano
2009-04-20 3:49 ` [PATCH RFC3.5 06/12] send-email: Cleanup and streamline the SMTP code in send_message Michael Witten
2009-04-20 3:49 ` [PATCH RFC3.5 04/12] send-email: Verification for --smtp-server and --smpt-server-port Michael Witten
2009-04-18 23:35 ` [PATCH RFC3.5 03/12] send-email: Interpret --smtp-server "" as "use a default" Wesley J. Landaker
2009-04-19 0:13 ` Michael Witten
2009-04-19 14:16 ` [PATCH RFC3.5.1 " Michael Witten
2009-04-20 1:41 ` [PATCH RFC3.5 " Junio C Hamano
2009-04-20 2:52 ` Michael Witten
2009-04-20 1:41 ` [PATCH RFC3.5 02/12] send-email: No longer repeatedly test if $smtp_server is a command Junio C Hamano
2009-04-20 2:37 ` Michael Witten
2009-04-20 4:21 ` Junio C Hamano
2009-04-20 4:53 ` Michael Witten [this message]
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=49ec020a.050cc00a.2a50.ffffd0e3@mx.google.com \
--to=mfwitten@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).