[Info-vax] BASIC (and Horizon)
Stephen Hoffman
seaohveh at hoffmanlabs.invalid
Wed Jan 31 11:05:22 EST 2024
On 2024-01-31 04:28:53 +0000, Dave Froble said:
> On 1/30/2024 9:40 AM, Chris Townley wrote:
>> On 30/01/2024 07:06, Dave Froble wrote:
>>> On 1/29/2024 8:02 PM, Arne Vajhøj wrote:
>>>> On 1/29/2024 7:50 PM, kludge at panix.com wrote:
>>>>> =?UTF-8?Q?Arne_Vajh=C3=B8j?= <arne at vajhoej.dk> wrote:
>>>>>> The code is VB6.
>>>>>>
>>>>>> But none of the problems are Basic specific. It is possible
>>>>>> to write the same bad code in C or Fortran or whatever.
>>>>>>
>>>>>> So it just shows that there are some really really bad programmers out
>>>>>> there.
>>>>>
>>>>> I have worked with people who could write spaghetti Fortran in any
>>>>> programming language available.
>>>>
>>>> "A real Fortran programmer can write Fortran in any language"
>>>>
>>>> Every time this comes up I post this Fortran/Pascal code:
>>>>
>>>> PROGRAM GOTOFUN(INPUT,OUTPUT);
>>>> LABEL L731,L113,L247,L588,L761,L922,L399,L601;
>>>> VAR LBL:INTEGER;
>>>> VAR I:INTEGER;
>>>> BEGIN
>>>> L731: GOTO L113;
>>>> LBL:=399;
>>>> L113: I:=0;
>>>> WRITELN(I);
>>>> L247: LBL:=601;
>>>> IF(I<0)THEN GOTO L588 ELSE IF(I=0)THEN GOTO L922 ELSE GOTO L399;
>>>> L588: I:=I+1;
>>>> WRITELN(I);
>>>> GOTO L399;
>>>> L761: CASE(LBL)OF 399: GOTO L399; 601: GOTO L601; END;
>>>> L922: I:=I+1;
>>>> WRITELN(I);
>>>> CASE(I)OF 1: GOTO L588; 2: GOTO L399; 3: GOTO L922; END;
>>>> L399: GOTO L761;
>>>> L601: END.
>>>>
>>>> :-)
>>>>
>>>> Arne
>>>>
>>>
>>> I'm amused every time the GoTo bashing begins.
>>>
>>> Not only is there nothing wrong when using a branch operation, when
>>> appropriate, just look at the assembler listings after compilation. Branching
>>> is just about all assembler does, as required.
>>>
>>> Now, I won't defend what I and most consider improper use of the poor
>>> misunderstood GoTo statement.
>>>
>>
>> But unless used very carefully, it can create horrible spaghetti like code, and
>> is also easy to screw up.
>>
>> Using proper structured constructs is much better - easier to read as well,
>> hence better maintainability.
>>
>
> Prey tell, what structured construct will perform cleanup and exit? I
> always expected a return from routines and such.
BASIC has its own variation on the classic TRY / THROW / CATCH /
FINALLY syntax:
WHEN ERROR IN
protected-statement [protected-statement,...]
USE
handler-statement [handler-statement,...]
END WHEN
But I'm mildly surprised it's lacking an ATEXIT or ilk. (I thought it
had that now, but I'm clearly mis-remembering.) I've used $dclexh and
ilk in various apps, or coded the app to release at rundown. (Not that
I prefer to have to implement manual cleanup, much as I'd like to avoid
explicitly deallocating memory in C. Garbage collection is so much
nicer, outside of kernel mode or other special app or context
requirements.)
Classic BASIC, Fortran, and C tend to be pretty bad at this
error-handling stuff (it's kinda been grafted on) without a fair amount
of work by the developer, and quite possibly with platform-specific
calls ($dclexh, etc) added. (Yes, I know about setjmp, atexit(), etc.
in C, and some other error-related syntax.) And yes, in BASIC, that
GOTO is one of the common ways to deal with errors, but I'd usually go
WHEN ERROR IN where I can. Or whatever other TRY / THROW / CATCH /
FINALLY / ATEXIT exists in the particular implementation.
And as for that earlier BASIC line number gibe, I'm sure most folks
working with BASIC on OpenVMS nowadays are using labels, as the labels
are just vastly more descriptive.
I've long thought this: "If the ERR function is used before an error
occurs or after an error is handled, the results are undefined" was
silly. UB? Seriously? Return some analog to SS$_NORMAL. Poof. No UB.
--
Pure Personal Opinion | HoffmanLabs LLC
More information about the Info-vax
mailing list