Skip to main content
Liberty BASIC Programmer's Encyc
Pages and Files
Graphics and Games
Strings and Text
Numbers and Math
Articles by Date
Table of Contents
TOS and License
Byte Mode Programming
Byte Mode Programming
By Mervin Faulkner Aug. 22, 2007
“Your technique will not work in our environment.” two young programmers said to me after my presentation on Hierarchical Go-TO-Less Programming at a Data Processing Management Association meeting in Canada.
“Why not?” I asked.
“We maintain a system that processes transactions that have 99 different transaction codes. We don't want all of the transactions to go through 99 If statements.”
“We did a study and found out 45% of the transactions are type 60 and 20% are type 40, so we check for these first and let the rest go through the rest of the Ifs.”
I picked up a napkin off a table near us and said “You say you are processing transactions that have a 2 byte transaction code with values from 1 to 99, right?”
I said “What if we look at it as 2 one byte codes instead?”
They said “What do you mean?”
“What if we compare the first byte to 0, if it is equal we will perform the
0-to-9 routine. If it is equal to 1 we will perform the 10-to19 routine. If it is equal to 2 we will perform the 20-to-29 routine etc. until we reach 9.
In 0-to-9 routine we test for 1 to 9. In the 10-to19 routine we test for 10 to 19 etc.
Do you see what I mean?”
They said “Yes, but the 60 and 40 codes will still go through more then 1 or 2 tests.”
I said “I agree. What will be the maximum number of tests any record will go through?”
They seemed to be a bit puzzled about the answer.
“20.” I said. “10 for the first byte, 0 to 9, and 10 in any routine. Example 90 to 99.”
“We see.” they said. “But it still makes the 60 and 40 codes go through more tests than they do now.”
I agreed, then said “You have to remember, you only write a program once but you maintain it forever. One thing you can count on in this world is that things change. Somewhere in the future, 1 year, 2 years, who knows when, your business will change and code 60 will no longer be the most common code. By the time you are informed and you do another study, you have processed a lot of transactions through 99 tests. With the method I have shown you, you will never go through any more than 20 tests regardless of what happens. No more studies, just let the program process the transactions!”
“It makes sense.” they said. They took the napkin I had been writing on and left.
Programming is still an art. It will never be a science with hard and fast rules. You have to be prepared to think outside of the box.
help on how to format text
Turn off "Getting Started"