Kurt McKee

lessons learned in production


Hey there! This article was written in 2014.

It might not have aged well for any number of reasons, so keep that in mind when reading (or clicking outgoing links!).

The Debris Cathedral

Posted 21 September 2014 in programming, teraterm, and work

For a very long time I've been writing code at my job that automates some very tedious tasks. It's not Python code, though! It's a macro language that has saved the company a lot of time and energy but suffers from severe limitations:

  • No scoping -- everything is in a global namespace.
  • No functions -- the entire language is based on keywords.
  • Incomplete support for lists -- the list can be defined but its length cannot later be checked.
  • Incomplete support for including code from other source files -- the included file will run from top to bottom and exit.
  • Inconsistent ordinal and cardinal numbering -- list indices start with '0', but string indices start with '1'.
  • Insufficient variable quantity and size limits -- one maximum quantity, for instance, is '9'.
  • GOTO.

A couple of years back I inherited some code and ran with it, but now I'm bumping up against these limits on a regular basis so I've had to get creative. Did you ever see Apollo 13? You know the scene where they gather scientists and engineers in a room, dump out a bunch of junk on the table, and tell the team "Make an oxygen filter"? I did that with this language.

I picked up INCLUDE in one hand and GOTO in the other and stared at the global namespace and decided "I'm going to emulate functions in a namespace." Now I'm able to call code in other files using this syntax:

callsub = 'namespace:function'
INCLUDE 'subroutine'

UPDATE: If you're interested, I've published the Tera Term subroutine source code.

The integer size limits were truncating calculations so (really heavy sigh) I wrote code that adds two hexadecimal strings of arbitrary length, thus avoiding integers entirely. That's something I did for fun in QBasic when I was 16, and the concept was revisited when I was wiring an adder on a breadboard in college, but it is staggering to have to do that to get real work done.

This is tested production code, so that's not going to get thrown away anytime soon. However, each time I bolt on another feature I feel like I'm building a cathedral out of rubble and debris. Relief is on its way, though: I've been building a foundation in Python that I believe I can shift this macro code over to. Then Python can handle the business logic and final validation while leveraging tested code to perform the required steps.

☕ Like my work? I accept tips!