[Coco] a couple of programming questions

Wayne Campbell asa.rand at yahoo.com
Thu Nov 19 14:52:07 EST 2009


1. I am dealing with code that is only executed once in the program. It is initialization of variables, initial display, and initial data. Which of the following is better, in terms of overall execution speed of the program?

A. At the top?

Start of Program

initialize
open input file (parameter test)
read top of input file and display data
create data files

Begin processing

--or--

B. At the bottom?

Start of Program

GOSUB <lref> (to the bottom)

Begin processing

End of Program

subroutines

Bottom of program

initialize
open input file (parameter test)
read top of input file and display data
create data files
RETURN

2. I am dealing with string literals of varying lengths. Some of them use the same word or words. Example:

cRLnR:="Renumbering Line References"
cRLtR:="Renumbering Literal References"

cSLnR:="Sorting Line References"
cSLtR:="Sorting Literal References"

To reduce program size, I am putting these literals into string variables defined in the initializations, and then referenced where they go.

Would it be faster, and/or reduce code size more if I used something like:

cRen:="Renumbering"
cRef:="References"
cLine:=" Line "
cLitl:=" Literal "
cSrtg:="Sorting"

cRLnR:=cRen+cLine+cRef
cRLtR:=cRen+cLitl+cRef

cSLnR:=cSrtg+cLine+cRef
cSLtR:=cSrtg++cLitl+cRef

The strings cRLnR, cRLtR, cSLnR and cSLtR would be referenced in the code, and the concantenations would occur in the initializations. But, would it really reduce code size or increase execution speed to do it the second way? Those four strings would still be the same length, and the only thing changing is the repetition of those string literals. Also, for each "substring", 3 additional bytes are being added to the code to reference them, and that's in each place where they are used.

Wayne


      



More information about the Coco mailing list