[Info-vax] BASIC (and Horizon)
Arne Vajhøj
arne at vajhoej.dk
Thu Feb 1 22:44:56 EST 2024
On 2/1/2024 10:38 PM, Dave Froble wrote:
> On 2/1/2024 9:49 PM, Arne Vajhøj wrote:
>> 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.
>
> Well, I'd use:
>
> Select <something>
> Case = "1"
> Some code
> Case = "2"
> Some other code
> End Select
That code does something completely different.
> 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.
To quote from Linux kernel coding style doc:
<quote>
Now, some people will claim that having 8-character indentations makes
the code move too far to the right, and makes it hard to read on a
80-character terminal screen. The answer to that is that if you need
more than 3 levels of indentation, you’re screwed anyway, and should fix
your program.
In short, 8-char indents make things easier to read, and have the added
benefit of warning you when you’re nesting your functions too deep. Heed
that warning.
</quote>
Arne
More information about the Info-vax
mailing list