by Tdarcos » Wed May 14, 2025 6:02 am
Why I had to rewrite the checking account program.
We had a check writing program, back before spreadsheet programs like Visicalc, or much of anything else we would take for granted today. The program was written in Applesoft Basic, and included the source code. I ended up making several changes to that program.
The routine that sorted checks was very slow. Create a file with a month's worth of records, and it could take 90 minutes to sort them. I examine the program ad discover whoever wrote it had picked the worst possible way to do a sort. You scan the first item against every one in the file, then if you find a lower entry, you swap the two. But then, it goes back to the first entry and scans all the items all over again.
I simplified this. After the swap, I continued searching, this time using the new first record as the target to search for a lower entry. Once I get to the bottom, I know the first item is the lowest one, so I don't need to scan it again, I start over with the second item, then the third, and so on, This is probably the best I can do because there wasn't a convenient source of knowledge available at my fingertips as now. In any case, this cut the sort time by 1/2. Still 45 minutes, but I didn't have a resource to find a better algorithm.
When listing checks, it showed them roughly 10 to a page, listing them with each of the fields on a single line. Check Number, date, name, purpose, amount and a blank line. At one point I was having trouble with figuring out what was where, so I wrote a 'quick and dirty" routine to write them in a condensed form: Each check on one line, if a field was too wide to fit I truncated the display of that item, allowing me to display about 60 items a page. Mrs. Rice comes out one day, looks at my "quick and dirty" listing, and asks, "How come we're not doing it this way?" Well, you don't have to hit me in the side of the head with a two-by-four, I made that the new display format for all new printed listings of checks.
One day, my boss calls me into her office and informs me the numbers are wrong. The program is getting incorrect results. With a bit of research, i discover there is an error in Applesoft Basic's floating-point routines. Small, unnoticeable errors in the internal values of each item add up to a discrepancy when summed. So I find an elegant solution. I change the internal representation of all checks to be integers. $7.50 is stored as 750, $104.35 as 10435, etc. When printing or displaying, I'd use the truncated value of the number /100, to get dollars, then the original number minus the truncated umber * 100 for the cents. Since all arithmetic is performed with integers, this eliminates the rounding errors.
After a year or two of this, Mrs. Rice decides to buy an IBM PC clone, a white box 8086 with two floppy drives and 256K of memory. I owned a )pirated) copy of MS-DOS and Lotus 1-2-3. I had a data cable to connect the serial port on the Apple II to the PC (both use incompatible disc formats), and transfer the checking accounts as CSV items so they can be imported into Lotus. Well, I have a month's worth of check data, and have it sort it, figuring that will take a while, only it comes back almost instantly. I figure there must be a problem, so I try again, same thing. I think maybe I tried doing a sort descending instead, and the same response, only it was in reverse order.
I think it dawned on me that there was nothing wrong, it simply had done the sort that fast. The same sort that took 45 minutes on the Apple II took 1/2 second[ on the PC. We could now do an entire year's worth of records in one spreadsheet, or would have, except the PC ran out of memory. After having had it just two weeks, Mrs. Rice had to take it back to the computer store that built it, and buy an upgrade to boost the memory to 640K.
After about 6 months or so of this, Mrs Rice buys a second computer, so she can do her own searches. So, I teach her how to use Lotus 1-2-3, and she has fun working on the files I've done, changing some of the entries to take less room or be clearer. One example: the payee on the entry for each check she wrote each month to Union 76 Oil Company for gasoline purchases, could be shortened to just "76." Well, one day I'm on my computer, she's on hers, and she spent about two hours making changes and examining data in one of the spreadsheets, and she wants to know how to get know something, either how to exit Lotus or load another spreadsheet, I forget which. so I tell her the / commands to use, and I'm about to tell her she needs to save what she's doing first, but she's a little too fast for me. She blows two hours of work in about two seconds. Fortunately, since she had a better idea of what she wanted to do, doing it over only took about an hour, but she learned a valuable lesson on making sure you save your work.
Then there was Othello. No, not the Shakespearean character, but the board game where you flip opponent's color discs to your color. Well, I had a copy of a program which was written in GWBasic that allowed playing it on the computer. Mrs. Rice loved that program, she had fun playing it. One time she played against me, and I'm probably not very good at it. (I would not have occurred to me to throw a game at the time; if I could have beaten her, I would have.) Then she wanted me to change the program so it would save her scores so she could tell how well she did. This allowed her to see how well she did over time.
One thing I did was to write a check writing program. I wrote it in GWBasic, it used a menu system, you could add payees, select which ones were recurring bills (mortgage companies) and ones with a different amount (like electric or gasoline). It would then print out the results on check stock which was on tractor feed paper. I believe we were using "3 stub" checks, top stub, which said who it was to, amount, date, purpose and duplicate of their address she kept, second stub was the info we gave them (like account number, along with the address (I think we had window envelopes for that purpose). Third stub, of course, was the check. This was useful, since I think she sent out about 30 or more checks a month. Car payment, mortgages on 8 properties plus utilities, photocopier rental, gas, management companies, etc.
Why I had to rewrite the checking account program.
We had a check writing program, back before spreadsheet programs like Visicalc, or much of anything else we would take for granted today. The program was written in Applesoft Basic, and included the source code. I ended up making several changes to that program.
The routine that sorted checks was [i]very[/i] slow. Create a file with a month's worth of records, and it could take 90 minutes to sort them. I examine the program ad discover whoever wrote it had picked the worst possible way to do a sort. You scan the first item against every one in the file, then if you find a lower entry, you swap the two. But then, it goes back to the first entry and scans all the items all over again.
I simplified this. After the swap, I continued searching, this time using the new first record as the target to search for a lower entry. Once I get to the bottom, I know the first item is the lowest one, so I don't need to scan it again, I start over with the second item, then the third, and so on, This is probably the best I can do because there wasn't a convenient source of knowledge available at my fingertips as now. In any case, this cut the sort time by 1/2. Still 45 minutes, but I didn't have a resource to find a better algorithm.
When listing checks, it showed them roughly 10 to a page, listing them with each of the fields on a single line. Check Number, date, name, purpose, amount and a blank line. At one point I was having trouble with figuring out what was where, so I wrote a 'quick and dirty" routine to write them in a condensed form: Each check on one line, if a field was too wide to fit I truncated the display of that item, allowing me to display about 60 items a page. Mrs. Rice comes out one day, looks at my "quick and dirty" listing, and asks, "How come we're not doing it this way?" Well, you don't have to hit me in the side of the head with a two-by-four, I made that the new display format for all new printed listings of checks.
One day, my boss calls me into her office and informs me the numbers are wrong. The program is getting incorrect results. With a bit of research, i discover there is an error in Applesoft Basic's floating-point routines. Small, unnoticeable errors in the internal values of each item add up to a discrepancy when summed. So I find an elegant solution. I change the internal representation of all checks to be integers. $7.50 is stored as 750, $104.35 as 10435, etc. When printing or displaying, I'd use the truncated value of the number /100, to get dollars, then the original number minus the truncated umber * 100 for the cents. Since all arithmetic is performed with integers, this eliminates the rounding errors.
After a year or two of this, Mrs. Rice decides to buy an IBM PC clone, a white box 8086 with two floppy drives and 256K of memory. I owned a )pirated) copy of MS-DOS and Lotus 1-2-3. I had a data cable to connect the serial port on the Apple II to the PC (both use incompatible disc formats), and transfer the checking accounts as CSV items so they can be imported into Lotus. Well, I have a month's worth of check data, and have it sort it, figuring that will take a while, only it comes back almost instantly. I figure there must be a problem, so I try again, same thing. I think maybe I tried doing a sort descending instead, and the same response, only it was in reverse order.
I think it dawned on me that there was nothing wrong, it simply had done the sort that fast. The same sort that took 45 minutes on the Apple II took 1/2 [i]second[[/i] on the PC. We could now do an entire year's worth of records in one spreadsheet, or would have, except the PC ran out of memory. After having had it just two weeks, Mrs. Rice had to take it back to the computer store that built it, and buy an upgrade to boost the memory to 640K.
After about 6 months or so of this, Mrs Rice buys a second computer, so she can do her own searches. So, I teach her how to use Lotus 1-2-3, and she has fun working on the files I've done, changing some of the entries to take less room or be clearer. One example: the payee on the entry for each check she wrote each month to Union 76 Oil Company for gasoline purchases, could be shortened to just "76." Well, one day I'm on my computer, she's on hers, and she spent about two hours making changes and examining data in one of the spreadsheets, and she wants to know how to get know something, either how to exit Lotus or load another spreadsheet, I forget which. so I tell her the / commands to use, and I'm about to tell her she needs to save what she's doing first, but she's a little too fast for me. She blows two hours of work in about two seconds. Fortunately, since she had a better idea of what she wanted to do, doing it over only took about an hour, but she learned a valuable lesson on making sure you save your work.
Then there was Othello. No, not the Shakespearean character, but the board game where you flip opponent's color discs to your color. Well, I had a copy of a program which was written in GWBasic that allowed playing it on the computer. Mrs. Rice loved that program, she had fun playing it. One time she played against me, and I'm probably not very good at it. (I would not have occurred to me to throw a game at the time; if I could have beaten her, I would have.) Then she wanted me to change the program so it would save her scores so she could tell how well she did. This allowed her to see how well she did over time.
One thing I did was to write a check writing program. I wrote it in GWBasic, it used a menu system, you could add payees, select which ones were recurring bills (mortgage companies) and ones with a different amount (like electric or gasoline). It would then print out the results on check stock which was on tractor feed paper. I believe we were using "3 stub" checks, top stub, which said who it was to, amount, date, purpose and duplicate of their address she kept, second stub was the info we gave them (like account number, along with the address (I think we had window envelopes for that purpose). Third stub, of course, was the check. This was useful, since I think she sent out about 30 or more checks a month. Car payment, mortgages on 8 properties plus utilities, photocopier rental, gas, management companies, etc.