From: David Kastrup <dak@gnu.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Supplant the "while case ... break ;; esac" idiom
Date: Tue, 25 Sep 2007 08:13:52 +0200 [thread overview]
Message-ID: <85hcljgtlr.fsf@lola.goethe.zz> (raw)
In-Reply-To: <7vodfr8wts.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Mon\, 24 Sep 2007 16\:31\:27 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> David Kastrup <dak@gnu.org> writes:
>
>> I am somewhat taken aback that a commit message considered offensive
>> (though I still have a problem understanding why and certainly did not
>> intend this) has been committed into master without giving me a chance
>> to amend it.
>
> Heh, that's simple. I changed my mind ;-)
>
> When A and B test for preconditions, and C, D, and E are
> operations with error reports as their side effects, we can
> write our loop in these forms:
>
> (1) while A && B && C && D && E || false; do :; done
> (2) while A && B && C && D && E || break; do :; done
> (3) while A && B; do C && D && E || break; do :; done
> (4) while :; do A && B && C && D && E || break; done
>
> and all of them are equivalent.
>
> But obviously the only sane version is (3).
Uh, it is the only version with a syntax error.
> If your complaint were against things like (1) and (2), I would have
> completely agreed with you. If you want "effects", you do so
> between do and done. Although you can use break between do and done
> if you need to conditionally break out of the loop after causing
> some effect there, between while and do is where you are only
> supposed to decide if you want to break out of the loop without
> causing "effects".
>
> But what you were complaining about was different.
Basically
while A && B || break; do C && D && E || break; done
> If we were to ignore broken shells that do not return success
> from a case statement with no matching pattern, the following
> two are equivalent:
>
> while case "$sth" in foo) break ;; esac; do ...; done
> while case "$sth" in foo) false ;; esac; do ...; done
>
> Their "case" are used to decide if you want to break out of the
> loop; the former is (1) being a bit more explicit, and (2) used
> to be a bit more efficient when false was not built-in.
As a completely irrelevant side note: the autoconf documentation
mentions that "false" is more portable than "true" since calling it
returns a non-zero exit status even when it is not installed or
built-in.
> Now the latter reason is mostly historical and it is not a valid
> reason to choose the former over the latter anymore. But that does
> not make it any more confusing than the latter to a person who knows
> what "break" means in a loop. An explicit 'break' is still more,
> eh,... explicit ;-)
>
> But the "break" never was the issue. Return value of "case" was.
I guess this has been a misunderstanding: for me, personally, the
break was the issue: I don't like breaking out of a condition, since
breaking for me is an action. I just used the fact that the BSD
shells happen not to grok the constructs (and actually through a
somewhat similar confusion between condition and action) to leverage
my dislike of this construct and propose a patch.
> The reason I took your patch and proposed commit log message
> (almost) as-is was because you rewrote "case" to "test".
Uhm, ok. It was a case of realizing "hm, this does not really look
much nicer" before I chose to switch to "test". In fact, there is one
case statement remaining which I rewrote in the previously discussed
manner, and it did not strike me as being much prettier. So maybe I
somewhat misjudged the core of my offended sense of aesthetics, but
the impetus of the discussion still carried into the commit message.
Alea iacta est ("The SHA-1 has been established").
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
next prev parent reply other threads:[~2007-09-25 6:14 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-21 21:43 [PATCH] Allow shell scripts to run with non-Bash /bin/sh Eygene Ryabinkin
2007-09-21 23:52 ` Junio C Hamano
2007-09-22 0:05 ` David Kastrup
2007-09-22 0:18 ` Junio C Hamano
2007-09-22 0:21 ` Junio C Hamano
2007-09-22 0:26 ` David Kastrup
2007-09-22 3:54 ` Eygene Ryabinkin
2007-09-22 4:06 ` David Kastrup
2007-09-22 6:58 ` Junio C Hamano
2007-09-22 7:34 ` Vineet Kumar
2007-09-22 11:07 ` David Kastrup
2007-09-22 6:54 ` Junio C Hamano
2007-09-22 21:37 ` Adam Flott
2007-09-22 8:32 ` Junio C Hamano
2007-09-23 8:31 ` Eygene Ryabinkin
2007-09-23 8:59 ` David Kastrup
2007-09-23 19:20 ` Junio C Hamano
2007-09-23 19:33 ` David Kastrup
2007-09-23 20:42 ` [PATCH] Supplant the "while case ... break ;; esac" idiom David Kastrup
2007-09-23 22:20 ` Junio C Hamano
2007-09-24 6:22 ` David Kastrup
2007-09-24 14:24 ` David Kastrup
2007-09-24 23:31 ` Junio C Hamano
2007-09-25 6:13 ` David Kastrup [this message]
2007-09-25 6:29 ` Junio C Hamano
2007-09-25 10:33 ` Johannes Schindelin
2007-09-25 10:46 ` Avi Kivity
2007-09-24 6:05 ` Mike Hommey
2007-09-24 6:26 ` David Kastrup
2007-09-24 6:30 ` David Symonds
2007-09-24 7:57 ` David Kastrup
2007-09-24 8:01 ` Pierre Habouzit
2007-09-24 8:04 ` Pierre Habouzit
2007-09-24 10:33 ` Johannes Schindelin
2007-09-24 11:21 ` Miles Bader
2007-09-24 11:35 ` Eygene Ryabinkin
2007-09-24 13:45 ` Miles Bader
2007-09-24 13:58 ` David Kastrup
2007-09-24 14:04 ` Johannes Schindelin
2007-09-24 14:10 ` David Kastrup
2007-09-24 14:58 ` Miles Bader
2007-09-24 16:24 ` Junio C Hamano
2007-09-24 11:39 ` David Kastrup
2007-09-24 8:29 ` David Kastrup
2007-09-22 2:33 ` [PATCH] Allow shell scripts to run with non-Bash /bin/sh Junio C Hamano
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=85hcljgtlr.fsf@lola.goethe.zz \
--to=dak@gnu.org \
--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.
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).