Re: Larkin, Power BASIC cannot be THAT good:
- From: John Larkin <jjlarkin@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 May 2009 06:36:14 -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.
Yes. I write thousands-of-lines programs, in various languages, that
are almost entirely flat, with every variable global and static, a big
GOTO state machine, with most subroutines done as JSR/RTS or
GOSUB/RETURN. If you do this carefully, you get fast, tight, clean
code, no possibility of memory or stack problems, and *zero* bugs. If
you do any programming carelessly, you get an ugly mess.
Anybody who ships embedded systems that have bugs is a bad programmer,
in any language. I'm on the mailing list for one analytical instrument
software package from a big company that uses all the latest languages
and version/bug control tricks. They average about ten new reported
bugs per week.
John
.
- Follow-Ups:
- Re: Larkin, Power BASIC cannot be THAT good:
- From: Joel Koltner
- 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: Soak the rich, lose the rich
- 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):
Relevant Pages
|