Re: Larkin, Power BASIC cannot be THAT good:
- From: "JosephKK"<quiettechblue@xxxxxxxxx>
- Date: Sat, 23 May 2009 19:05:06 -0700
On Thu, 21 May 2009 00:28:08 -0700 (PDT), Tim Williams
<tmoranwms@xxxxxxxxx> wrote:
On May 21, 12:28 am, "JosephKK"<quiettechb...@xxxxxxxxx> wrote:
Over 20 years ago a coworker of mine wrote a comefrom static analysis
program to analyze his programs. He was rather shocked to see how
much he had been abusing goto. And this was with a version of basic
that had subroutines with parameters.
I regularly use QuickBasic, which is quite capable of OO style
subroutines (although calling QB OO, with its narrow "object"
functionality, is a stretch), but which of course allows GOTOs. I
find there are a number of places were GOTO is simply too useful to
pass up. Here's a recent example:
.
.
.
FOR i = 1 TO LEN(In$)
k = ASC(MID$(In$, i, 1))
l = Ascii2Seven(k)
m$ = Num2Hex$(l AND 255)
GOSUB PrintByte
IF l > 255 THEN
m$ = Num2Hex$((l AND &HFF00&) \ &H100)
GOSUB PrintByte
END IF
NEXT
.
.
.
So it chews through In$, one byte at a time, doing whatever
Ascii2Seven does (ooh, a user-defined function!). The rub is, for
expandability reasons, Ascii2Seven may return a one-digit number
(i.e., values 0 to 255) or a two-digit number (I believe the sign bit
is set in this case). Printing the other byte requires a seperate
call to PrintByte, for state reasons. SUB would be inelegant here
because a number of variables would either have to be passed as
operands or SHAREd globally, neither of which really make any sense.
Printing one or both bytes at the same time (which could, in
principle, be done with one call to, say, PrintSeven instead of
PrintByte) just moves things around and meets the same problem.
Other times, I've used GOTO or GOSUB to call a routine which has a lot
of common variables (i.e., its scope includes main) or to branch to a
single routine from multiple exit points out of a SELECT CASE or
somesuch.
Most of the time, I do write SUBs and FUNCTIONs, great for compact
bits of code that might be useful in other places, or which are fairly
specialized but have little effect on other parts of the program (for
instance, a game engine, menu, physics, AI and other systems can all
be sectioned into seperate subroutines, for the most part). On
average I would suppose GOTO and GOSUB count as "rare" (<1% of all
subroutine calls?) in my usage.
What really matters, and what everyone time and time again keeps
missing is, GOTO and SUB must both be used responsibly. Since there
is no check on programmers being responsible, there is no check on
programmers producing managable code, regardless of language
structure.
That this argument even exists is proof that programmers are
egotistical douchebags who don't want to accept responsibility when
they write shitty code. And yes, I'm calling out *everyone* on this
argument: you, Dijkstra, everyone who's tried arguing this non
sequitur. Dijkstra was smart but that doesn't preclude him or anyone
else from being a dbag. ;-)
Tim
There is a fundamental difference between goto and gosub. It is an
important one, subroutine invocation saves time and code space without
the biggest problems of goto.
.
- Follow-Ups:
- Re: Larkin, Power BASIC cannot be THAT good:
- From: John Larkin
- Re: Larkin, Power BASIC cannot be THAT good:
- References:
- Re: Larkin, Power BASIC cannot be THAT good:
- From: John Larkin
- Re: Larkin, Power BASIC cannot be THAT good:
- From: Nico Coesel
- Re: Larkin, Power BASIC cannot be THAT good:
- From: John Larkin
- Re: Larkin, Power BASIC cannot be THAT good:
- From: Jan Panteltje
- Re: Larkin, Power BASIC cannot be THAT good:
- From: John Larkin
- Re: Larkin, Power BASIC cannot be THAT good:
- From: Nobody
- Re: Larkin, Power BASIC cannot be THAT good:
- From: Phil Hobbs
- Re: Larkin, Power BASIC cannot be THAT good:
- From: JosephKK
- Re: Larkin, Power BASIC cannot be THAT good:
- From: Tim Williams
- Re: Larkin, Power BASIC cannot be THAT good:
- Prev by Date: Re: OT: Time to dust off the bomb shelter!
- Next by Date: Re: Larkin, Power BASIC cannot be THAT good:
- Previous by thread: Re: Larkin, Power BASIC cannot be THAT good:
- Next by thread: Re: Larkin, Power BASIC cannot be THAT good:
- Index(es):
Loading