[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: Morris's 'program that abbreviates words' [was: various]



Reply to note from "Morris Krok"  Sat, 8 Jun
2002 19:30:01 -0700

> Some years back I wrote a program that abbreviates words which
> I am inserting, I wonder if the gurus could give some tips how
> it can be improved or streamlined.

Morris:

Without even understanding what it is your program sets out to do,
I'd urge you to pay attention to two things: unnecessary SUbroutines
and unnecessary LaBels-GoLaBels.

You have several SUbroutines that are invoked only once. In general
(there are exceptions), there is no reason to use a SUbroutine for a
procedure that occurs only once in a program. Eliminate the SUb and
move the procedure up into the main routine. Furthermore, you've
defined several SUbroutines (24, 25 and 34) that are not used at
all. Delete those.

You have a series of GoLaBels which point to LaBels that are,
logically, traversed only once (any repetitions being handled by the
loop ...). Loops aside, the only functional
reason to use a LaBel is to be able to GoLaBel to it from at least
two different locations in your code. Otherwise, just do what you
need to do where you need to do it, and move on. GoLaBels slow a
program down and make it hard to read. It's like trying to trace a
single strand of spaghetti in a heaping, sauce-drenched bowl -- why
this style of programming is deprecated as "spaghetti code".

Another thing about LaBels: where possible (and usually it is
possible), structure your code so that GoLabels jump backward rather
forward. Forward jumps, especially long ones, are appreciably
slower.

Is there a reason to end with ? As you know,  halts all
other running XPL processes, and should therefore be used with care.
Absent a specific reason to use it, stick with .

Do you really need that func SI (Set Insert typing mode)? Offhand,
I don't see where your program inserts any text. Furthermore, you
can always avoid forcing Insert mode by saving any
text_to_be_inserted to a Save/Get and GTing it. GT inserts text
regardless whether the current manual input mode is Insert or
Overstrike. For example, instead of "GT SI Hello, there!" you'd
write "GT ". This is important
because, as far as I know, you can't test for Insert/Overstrike mode
in Xy3 -- idiomatically, your code is firmly planted in 3 -- and
therefore can't restore Insert/Overstrike to its original condition
on EXit. (Xy4+ has , but  sidesteps the issue
entirely.)

On a stylistic level, I would suggest RENUMBERing your Save/Gets to
a continuous range, and RELABELing the two remaining LaBels-GoLaBels
to short, alphabetical names. The reasons for this (which, in fact,
aren't solely stylistic and have important substantive implications)
are explained in REORGNIZ.DOC, available at XyWWWeb.

To illustrate the above, here, for study, is a slimmed-down (27%
smaller) rewrite of your program, identical in operation to the
original:

XPLeNCODE v2.0
b-gin [UNTITLED]
{<}SU01,[YD_]# [LE_] [CL_][CL_][DW_][CL_][RC_][BF_][LB_][CP_]
[YD_][LB_][CR_][BC_]ci /a//[XC_][LB_][CR_][BC_]ci /e//[XC_][L
B_][CR_][BC_]ci /i//[XC_][LB_][CR_][BC_]ci /o//[XC_][LB_][CR_
][BC_]ci /ufile://[XC_][CH_][LB_][DF_]{>}{<}SU02,[CP_][YD_][N
W_][RW_][LB_][DW_][BC_]seb /#/[XC_][RC_][RC_][CH_][MV_][YD_][
CD_]{>}[SI_]{<}LBA{>}[LE_] [CL_][CL_][DW_][BC_]se .[WA_].[XC_
]{<}IF{<}ER{>}{>}{<}LBB{>}[YD_][TF_][CH_]{<}EX{>}[cr|lf]{<}EI
{>}{<}SV03{>}{<}SX04,@siz({<}IS03{>}){>}{<}IF{<}PV04{>}==7{>}
[YD_][DF_][CR_][CR_][DF_][LB_][CP_] [YD_][LE_][CL_][CL_][DF_]
[CR_][CR_][DF_][LB_][CR_][CR_][CP_][YD_]{<}GLA{>}[cr|lf]{<}EI
{>}{<}IF{<}PV04{>}==8{>}[YD_][DF_][CR_][CR_][CR_][DF_][LB_][C
P_] [YD_][LE_][CL_][DF_][CR_][DF_][LB_][CR_][CR_][CR_][CP_][Y
D_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==6{>}[YD_][DF_][CR
_][DF_][LB_][CP_] [YD_][LE_][CL_][CL_][DF_][CR_][CR_][DF_][LB
_][CR_][CP_][YD_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==9{>
}[YD_][DF_][CR_][CR_][CR_][DF_][LB_][CP_] [YD_][LE_][CL_][CL_
][DF_][CR_][CR_][DF_][LB_][CR_][CR_][CR_][CP_][YD_]{<}GLA{>}[
cr|lf]{<}EI{>}{<}IF{<}PV04{>}==10{>}[YD_][DF_][CR_][CR_][DF_]
[LB_][CP_] [YD_][LE_][CL_][CL_][CL_][DF_][CR_][CR_][CR_][DF_]
[LB_][CR_][CR_][CP_][YD_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04
{>}==11{>}[YD_][DF_][CR_][CR_][CR_][DF_][LB_][CP_] [YD_][LE_]
[CL_][CL_][CL_][DF_][CR_][CR_][CR_][DF_][LB_][CR_][CR_][CR_][
CP_][YD_][NW_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==1{>}{<
}GLB{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==5{>}[YD_][DF_][CR_][CR
_][DF_][LB_][CP_] [YD_][LE_][CL_][DF_][CR_][DF_][LB_][CR_][CR
_][CP_][YD_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==4{>}[YD_
][DF_][CR_][DF_][LB_][CP_] [YD_][LE_][CL_][DF_][CR_][DF_][LB_
][CR_][CP_][YD_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==3!{<
}PV04{>}==2{>}[YD_][DF_][CR_][DF_][LB_][CP_] [YD_]{<}GLA{>}[c
r|lf]{<}EI{>}{<}IF{<}PV04{>}==12{>}[YD_][DF_][CR_][CR_][CR_][
CR_][DF_][LB_][CP_] [YD_][LE_]
[CL_][CL_][DF_][CR_][CR_][DF_][LB_][CR_][CR_][CR_][CR_][CP_][
YD_]{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==13{>}{<}GT01{>}[
CR_][CR_][CR_][DF_][LB_][CP_][YD_] [LE_][CL_][CL_][DF_][CR_][
CR_][DF_][LB_][CR_][CR_][CR_]{<}GT02{>}{<}GLA{>}[cr|lf]{<}EI{
>}{<}IF{<}PV04{>}==14{>}{<}GT01{>}[CR_][CR_][CR_][DF_][LB_][C
P_][YD_] [LE_][CL_][CL_][CL_][DF_][CR_][CR_][CR_][DF_][LB_][C
R_][CR_][CR_]{<}GT02{>}{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>
}==15{>}{<}GT01{>}[CR_][CR_][CR_][CR_][DF_][LB_][CP_][YD_] [L
E_][CL_][CL_][DF_][CR_][CR_][DF_][LB_][CR_][CR_][CR_][CR_]{<}
GT02{>}{<}GLA{>}[cr|lf]{<}EI{>}{<}IF{<}PV04{>}==16{>}{<}GT01{
>}[CR_][CR_][CR_][CR_][CR_][DF_][LB_][CP_][YD_] [LE_][CL_][CL
_][CL_][DF_][CR_][CR_][CR_][DF_][LB_][CR_][CR_][CR_][CR_][CR_
]{<}GT02{>}{<}GLA{>}[cr|lf]{<}EI{>}{<}EX{>}[cr|lf]
-nd
XPLeNCODE

--
Carl Distefano
cld@xxxxxxxx
http://users.datarealm.com/xywwweb/