Goldenseal Pro Progress- Outline View & ARC (Aug 30)

Last week I mentioned a mystery problem we were fighting: the outline view in our main window used to work OK. Then suddenly, it didn’t.

Folks on the Cocoa-dev mailing list were very helpful, with many suggestions on what might fix it. We tried them all, but nothing worked. Along the way our staff learned way too much about Apple’s memory system. It’s called ARC (Automatic Reference Counting). Developers on the list think it’s the bees knees. It is certainly better than the old manual system. Except that ARC was deleting our outline view, even though code was there to prevent it.

These days, most programming languages manage memory automatically. Stuff sticks around as long as you need it, then disappears when it’s no longer needed. Popular languages like Java, Python and C# use “garbage collection” to accomplish that. It’s probably not the ideal way to manage memory, but it works fairly well. And it makes life much, much easier for programmers.

Most of Goldenseal is written in C++. It is considered a difficult language, mostly because it doesn’t have garbage collection. On the other hand, C++ does give better performance. It’s also fairly easy to debug. There are many ways for programmers to manage memory reliably, and the language keeps improving every year.

Using C++ is a bit like, say, using power tools. Sure, they have sharp whizzing parts that can easily remove your limbs or digits. But they include guards and safety features. If you use power tools carefully, they get the job done safely.

Apple’s ARC seems to be somewhere in between C++ and Java. It promises easy memory management, but there are many “gotchas” that we discovered this week. It is not easy to debug. It definitely is not as simple as the garbage-collected languages. That applies both to the Objective-C language that we use for the new Goldenseal code, and to Apple’s new Swift language.

I hate to criticize a trillion-dollar company, but our life would be way easier if Apple used C++, Python, Java, or pretty much any other programming language. There’s a reason everyone else uses those other languages.

At any rate, we did find a fix. Our code worked OK until we made changes in June, and we can revert those changes. Theoretically it will leak some memory, but it won’t be very much. It won’t happen at all for most users.

With hindsight, we could have just reverted right away, and saved two weeks. But we learned stuff along the way. It was good to find out we hadn’t done anything obviously stupid.  If our staff did cause the problem, it was something extremely subtle. It may even be a bug in Apple’s ARC code, though it’s not worth another week of digging to find out for sure.

At least Goldenseal Pro is back on track. This is not the first time we’ve bogged down in Cocoa complexities, and lost weeks or months.

Dennis Kolva
Programming Director

Goldenseal Pro Progress- Outline View (Aug 23)

A while back I mentioned how easy it was to set up the Goldenseal Pro outline view. It replaces the menus at the top, and does an excellent job of organizing things. I assumed that NSOutlineView probably was so reliable because it also runs the Macintosh Finder.

Unfortunately, I spoke too soon about that. This week we opened a few items, and the outline view stopped working. Clicking did nothing.

Usually our staff is very methodical. We add new code, make sure it works, and then commit it to the source control system. Nearly always, the process works well. Stuff improves, step by step. Unfortunately, a few times a year we miss something subtle, or change something with unintended consequences. It becomes a bug that rears its head weeks or months later. This is one of those times.

The first thing we did was check the weekly full-project backups, to see when it broke. Recent backups also had the problem. The June 2 backup worked OK. The June 9 backup didn’t. Most of the changes that week were related to bank transactions, and unlikely to affect the outline view. That week we did add a new NSSplitView to make the window resizable. So we removed that, but it didn’t help.

Next step was to rebuild from source control, to narrow it down to a shorter time range. June 7 was OK. June 8 wasn’t. Most of the changes that day were just accounting stuff, but we also started to add “weak” references. It’s an Apple thing that prevents memory leaks. That seemed like the smoking gun.

To test it, we set some breakpoints. Sure enough, the outline table was deleted randomly, after running a while. In earlier builds it stuck around. It didn’t work because it wasn’t there.

Apples ARC (automatic reference counting) is hard to debug. In C++ you can set a breakpoint right where an object is deleted, to see what killed it. Objective-C with ARC does the deletion some random time later. That makes it very difficult to find the cause of death.

Our staff spent a couple days stepping through code and reading more about ARC. It’s more complicated than we first thought. One website describes ARC as “kind of like a Japanese B-horror movie”. That seems accurate. We spent several weeks in April and May, struggling with a similar problem in the tab view.

Today we got too frustrated, and gave up for a while. It’s time to get back to more productive programming.

The Apple developer list is often helpful for odd problems, so we just posted a message there. This is the kind of enigma that may be solved in a dream at 3 AM, days or weeks later. Worst case, we get one support incident with Apple per year. It may be time to use it.

Dennis Kolva
Programming Director


Goldenseal Pro Progress- Links (Aug 15)

Goldenseal stores many different types of business data. There are customers, suppliers, employees, projects, purchases, estimates, sales, payroll and bank transactions. Then another 40 or 50 special items like change orders and equipment hours. Then another 70-odd small details like sales tax rates and payroll tax tables.

Navigating around in that sea of information is challenging. Goldenseal makes it easier by providing may ways to see linked info via a click or menu choice.  For example, a material purchase has quick links to the supplier account and job account, plus the bank transaction that paid for it. Project accounts have buttons to view job costs, contacts and other details. Pretty much everything has a quick link to something else that’s related.

The current Goldenseal version has separate windows for each type of data. When you click a link, it opens another window for it. Most of the windows are about half the size of a laptop screen, or 1/6 of a big desktop screen. It’s easy to end up with 20 or 30 Goldenseal windows scattered about. Not the ideal way to manage a virtual desktop. It’s kinda like strewing papers across your actual desktop.

Goldenseal Pro uses an outline and tabs to organize things into a single window. You also can open separate windows just like the old style, but you probably don’t need to. The new interface is the virtual equivalent of putting your paperwork into folders and binders. Tidier. Quicker access.

With the new interface, the question is: how best to show linked records. There are five choices:

* Open a new window, just like the current version.
* Open a smaller, simpler window, with just one record and no fancy controls.
* Open a temporary panel that drops down in front of the current record.
* Add a tab for the record, and bring it to the front.
* Add a tab, and leave it somewhere behind the current record.

The past couple weeks, our staff has been experimenting with all of them. We are still deciding which are the most useful and the least annoying.

Actually, there’s a 6th choice. For a while, we showed breakdowns in a slide-out drawer on the right side. That would also be a great way to view linked records. Related and connected. Drawers used to be a standard Apple interface feature, but they are deprecated. Goldenseal Pro used them for a while despite that, but ran into bugs we couldn’t fix. An attached window may still be the ideal solution for linked records (and breakdowns), but it won’t happen for Goldenseal Pro 1.0. It will be complicated to program it from scratch, and the deadline for 64-bit conversions is coming soon.

This sort of interface design needs a few weeks of real-world testing and usage. Link display may be something that deserves a Preferences option, or a way to control how it looks via a modifier key.

Dennis Kolva
Programming Director