Strings (Jan 13)

Last week, our staff finished a grueling 10-day stretch of work on payroll tax tables. In a good year it only takes 3 days.

Federal tables changed for all 50 states + DC. For decades the US got by with just 2 step tables, but now there are 8 of them. Last year we added one set of new tables, but we missed some and added them this year. A record number of states also changed their withholding formulas, including a few major rewrites.

We returned to work on the Layouts window, but soon ran into distractions.

Some menu commands in the current Goldenseal don’t yet have a place in TurtleSoft Pro. We needed one to help with testing. Adding a button to the top bar made the most sense, but it’s getting crowded up there. So we tried moving things around to give it more space. Qt is not very good at that kind of setup, but we finally produced something that is a bit better.

Then there were mystery crashes in CTextString: the class we use to store text. It’s not the first time it has done that. In the past we rewrote offending code to avoid the errors, but a better cure is to rewrite CTextString.

When we started Goldenseal, there was no standard C++ library. Everyone wrote their own string class to handle text. We adapted ours from the one in the PowerPlant framework. It is very 1990s programming. More like C than C++. Text is stored in chunks of raw memory, with raw pointers to access it. That’s just how things were done back in those days.

Raw C is a bit like using a circular saw with all the safety guards removed. Just a sharp spinning blade on a motor. You can do all the same stuff with it, and it works much better for some tasks. But, yeah, in the long run you’ll keep more fingers if you use the safer version.

The modern C++ standard library has std::string. TurtleSoft Pro already uses it for a few things. It’s safer, more versatile, and more reliable than CTextString. Not surprising, because thousands of programmers work on the C++ libraries, while TurtleSoft has only had a few. Compared to the C++ gurus, we also are amateurs. Our strength is construction accounting and estimating knowledge, not the dark arts of C++ memory calls.

So, rather than debug the mystery errors, we updated CTextString to use a std::string instead of raw C memory. We can’t swap over entirely, because CTextString does many things that are specific to our app. So it owns a std::string that does the heavy listing, then keeps on doing what it used to.

This is one of those big changes that risks breaking some things, but ends up better (probably) in the long run. Almost like, say, jacking an old house and putting in a new foundation. Text strings are that basic.

With the change, there are places where we can remove big chunks of complicated code. For example, Goldenseal converts text to a decimal number via a loop through each character. It ignores non-digits, deals with negatives, and checks for decimal points (period or comma depending on location). There’s special code for extra decimal points. The C++ standard library has a function to convert text to decimals, so the new version is just one line.

Our staff accomplished some major successes last month, but this change is deeper and riskier. Right now it compiles OK and doesn’t crash. We still need to test every command and make sure the output hasn’t changed. Wish us luck!

Dennis Kolva
Programming Director
TurtleSoft.com

Author: Dennis Kolva

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