Zeros & Ones (Nov 19)

You probably start with number one whenever you list things. Generally that is what the Goldenseal code does, too. 1, 2, 3, 4, 5… The current version is based on a framework called PowerPlant, which also starts lists and table rows at number 1.

The C++ language starts lists at zero. 0, 1, 2, 3, 4… Hard-core programmers will give you all sorts of reasons why zero is better than one. The Cocoa framework that we used for 3 frustrating years is also zero-based. So is the Qt framework that we use now.

When two number systems collide, it is very easy to get “off by one” bugs. There are many ways to make those even when you don’t have two different numbering systems, but a mix of 1-lists and 0-lists makes it extremely easy to err that way.

When we set up breakdown tables last spring, our staff solved the conflict by using 0-based rows and columns in the Qt tables that are visible on the screen, with a conversion when they talk to the original Goldenseal tables that lurk in the background. Add one when going down, subtract it when going back. That way the existing business logic still worked OK.

For action commands, it wasn’t worth keeping the original Goldenseal tables. Not enough code in them to justify their existence. So, those dialogs do everything with 0-based tables. Unfortunately, it created many off-by-one errors. Even worse, they often are the nastiest kind of bug. Fix one, and it breaks something else.

It finally was time to refactor the code and make it less prone to off-by-ones. We did that this week. To start, we added a Q to the name of everything that is 0-based. That didn’t solve any problems by itself, but when we fix bugs, now they stay fixed and don’t break something else. It’s more obvious what needs a 0 and what needs a 1.

The deep, deep root of the problem is that computer languages evolved. They are the result of many small short-sighted decisions, rather than a master design. Many details seemed like good ideas at the time. Then they turned out to be monsters later.

It’s kinda like what you face as a vertical human. The standard mammal body plan has four feet on the ground, so your hips and neck each had to rotate 90° to make the new posture work. Backbones were forced into a tight curve, with a painful change of loading direction. Necks rammed into where teeth used to be, pushed them together and made them crooked. For the most part the design works, but it’s buggy.

This is a roundabout way of saying that we are still working on the action commands for TurtleSoft Pro. They are more difficult than expected. We’re making progress, but it’s slower than we’d like.

Dennis Kolva
Programming Director
TurtleSoft.com

Author: Dennis Kolva

Programming Director for Turtle Creek Software. Design & planning of accounting and estimating software.