From: J�rgen Exner on
Sherm Pendley <sherm.pendley(a)gmail.com> wrote:
>I think we agree more than not - note that I grouped the conditionals
>at the top of the loop body, with the ellipses representing additional
>code appearing after them. I wouldn't scatter them throughout the loop
>body, unless I had a *very* good reason for doing so.

:-)

jue
From: J�rgen Exner on
Ben Morrow <ben(a)morrow.me.uk> wrote:
>I don't know much about proving programs, but do additional exit points
>really make it any harder than stuffing everything into the conditional?
>Either way, you end up having to deal with the complexity of the
>algorithm somewhere.

Well, depends. If it's just a top-level series of
last if (C1);
last if (C2);
last ....
then no, not really. You just collect all of them and you know that
after the loop at least one of them is true, i.e.
C1 or C2 or C3 or ...

The tricky and rather tedious part are those assertions derived from the
rest of the code that was executed until each last() call somewhere deep
down a deeply nested loop with many conditionals. Those have to be
collected, too, or'ed too, and then simplified. And that's a pain in the
lower rear.

jue
From: Ben Morrow on

Quoth J�rgen Exner <jurgenex(a)hotmail.com>:
> Ben Morrow <ben(a)morrow.me.uk> wrote:
> >I don't know much about proving programs, but do additional exit points
> >really make it any harder than stuffing everything into the conditional?
> >Either way, you end up having to deal with the complexity of the
> >algorithm somewhere.
>
> Well, depends. If it's just a top-level series of
> last if (C1);
> last if (C2);
> last ....
> then no, not really. You just collect all of them and you know that
> after the loop at least one of them is true, i.e.
> C1 or C2 or C3 or ...
>
> The tricky and rather tedious part are those assertions derived from the
> rest of the code that was executed until each last() call somewhere deep
> down a deeply nested loop with many conditionals. Those have to be
> collected, too, or'ed too, and then simplified. And that's a pain in the
> lower rear.

Yes, I can see that. But is it any *less* painful if those conditionals
are lifted up into the loop condition (especially if they have
side-effects)? It seems to me you're just requiring that the code author
make their code less comprehensible for the benefit of some hypothetical
(probably non-existent) code prover, which isn't a win.

Of course, under some circumstances the algorithm can be simplified into
one which *can* be easily expressed in terms of while-without-last, and
in others an alternative algorithm which can be would work just as well.
I would agree with you that in that case it should be. In the OP's case,
however, I don't see any way of simplifying the basic

while (1) {
<setup>
last if <condition depending on setup>;
<actions>
}

structure that isn't harder to understand and more error-prone. The
Pascal-ish replacement of

my $continue_looping = 1;
while ($continue_looping) {
my $page = get ...;
$continue_looping = 0 unless $page;
write_file ...;
}

just hides the control flow behind a variable, which means you can't
even search for 'last' to find possible exit points.

Ben

From: Tad McClellan on
Ben Morrow <ben(a)morrow.me.uk> wrote:
>
> Quoth "Peter J. Holzer" <hjp-usenet2(a)hjp.at>:
>> On 2010-07-31 16:42, J�rgen Exner <jurgenex(a)hotmail.com> wrote:
>> > "Thomas Andersson" <thomas(a)tifozi.net> wrote:
>> >>The loop has been rewritten and workds as intended now, using last to exit
>> >>on the two possible conditions. Now look like this:
>> >>
>> >>while (1) {
>> >
>> > Ouch, this hurts! Usually this line indicates a deamon which is never
>> > supposed to terminate.
>>
>> Maybe. Personally I never use while (1), I prefer for (;;) instead.
>> But neither implies that the loop is really infinite: It may (and often
>> is) be left with last or return.
>
> Actually it will *always* be left in some way, if only due to the heat
> death of the Universe... :)


LOL!


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
From: Sherm Pendley on
Ben Morrow <ben(a)morrow.me.uk> writes:

> Actually it will *always* be left in some way, if only due to the heat
> death of the Universe... :)

Isn't there a prize for solving the halting problem? :-)

sherm--

--
Sherm Pendley <www.shermpendley.com>
<www.camelbones.org>
Cocoa Developer