[Info-vax] BASIC (and Horizon)
Dave Froble
davef at tsoft-inc.com
Thu Feb 1 22:38:21 EST 2024
On 2/1/2024 9:49 PM, Arne Vajhøj wrote:
> On 1/31/2024 9:49 PM, Lawrence D'Oliveiro wrote:
>> On Wed, 31 Jan 2024 19:29:14 -0500, Arne Vajhøj wrote:
>>> That code would look a lot cleaner if the do while(false) loop got
>>> removed and the relevant breaks got replaced by goto's.
>>
>> Show us how you would do it. I can take you through my code step by step,
>> block by block, if that will help.
>
> It is pretty simple.
>
> do {
> allocate(o1);
> ...
> if(...) break;
> ...
> } while(false);
> deallocate(o1);
>
> can be done as:
>
> allocate(o1);
> ...
> if(...) goto cleanup;
> ...
> cleanup:
> deallocate(o1);
>
> The first piece of code is pretty bad as it confuses the
> reader by using a loop and the break is not very
> self documenting.
>
> The second piece of code is straight forward to read
> despite using goto.
>
> It gets even more clear in the nested case.
>
> do {
> allocate(o1);
> ...
> if(...) break;
> ...
> flag = FALSE;
> do {
> allocate(o2)
> ...
> if(...) {
> flag = TRUE;
> break;
> }
> ...
> }
> deallocate(o2)
> if(flag) break;
> ...
> } while(false);
> deallocate(o1);
>
> vs:
>
> allocate(o1);
> ...
> if(...) goto cleanup_1;
> ...
> allocate(o2);
> ...
> if(...) goto cleanup_1_and_2;
> ...
> cleanup_1_and_2:
> deallocate(o2);
> cleanup_1:
> deallocate(o1);
>
> The nested do while loop is a big mess. The goto solution
> is still simple.
>
> Arne
>
Well, I'd use:
Select <something>
Case = "1"
Some code
Case = "2"
Some other code
End Select
No need for the dreaded GoTo statement ...
But even that can be abused.
Got a friend that got carried away with Select and indenting.
When the Select statements got nested a dozen times, and indents became 8-10
tabs, and the code for each CASE was several pages long ...
If the damn code was going to be so massive and complex, he should have just
branched/performed/whatever to a separate place to do all that work.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: davef at tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
More information about the Info-vax
mailing list