Archive for the ‘Programming’ category

The Technical Story of the Adium Fixes in Version 0.32

December 31, 2008

Here are the problems I had updating my Adium plugin for version 1.3 of Adium, in the order they were discovered.

First, Adium plugins now must declare a minimum version of Adium. If you don’t say “I require at least version x.x of Adium” then Adium assumes the plugin is too outdated to work and won’t load it. (Turns out that was the right assumption for my plugin!) You declare a minimum supported version by adding a value for AIMinimumAdiumVersionRequirement in your info.plist.

Second, AppleScript support for getting the current status message is broken. So I had to add a way for IMLocation to ask the plugin for the current status message. (It also means that I’m stuck requiring a plugin for any integration with Adium, which is a shame.) For what it’s worth, I prefer the new AppleScript interface for Adium (modulo the “not working right now” bit).

Third, the way plugins are written for Adium has changed. From a software-engineering perspective the changes are for the best, and will make a better Adium. But of course I’m complaining because I had to do more work :-).

Plugins used to inherit from AIPlugin, which had a field named adium that was analogous NSApp. Now plugins conform to the AIPlugin and AIPluginInfo protocols, and can inherit from anything. (Hint: #import <Adium/AISharedAdium.h> will give you the adium back, but now as a proper global.)

Fourth, the way I was updating the status message for Adium wasn’t working so well. And the more I looked into it, the more it looks like very little (if anything) was changed in Adium. It just had a different way of dealing with statuses that wasn’t working out all that well for me.

Solving this issue took me longer then solving all other problems combined. But in the end it was definitely worth it. I have better integration with Adium now. And I was able to get rid of some update-throtteling code of mine that prevented too many changes to the status being made too quickly (Adium is now smart enough to do that internally!).

Fifth, testing, testing, testing. All code that’s written must be tested. And because so many changes were made to Adium as well as my plugin’s code, I waited a few days before officially pushing my changes, to allow more time for bugs to be discovered.

Advertisements

Leopard Only

December 22, 2008

I owe you an explanation of why version 0.30+ of IMLocation now requires Mac OS X 10.5 Leopard. Originally IMLocation ran on both Leopard and Mac OS X 10.4 Tiger, so why the change?

As I write this, the Omni Group’s data shows 54.7% of people still using Tiger. The number is decreasing, but it’s still a majority. Alienating a majority of potential users is not something I do lightly.

Practical Reasons

Automator

At the highest level, IMLocation does stuff so you don’t have to. It all started as a small project in college to get my computer to update my iChat status when I changed classes. That means IMLocation is fundamentally an automation tool.

In Tiger, Apple introduced, “Automator, your own personal robotic assistant that will take care of whatever task you give it.” But, partly out of shortsightedness, and partly because there wasn’t (yet) support for editing Automator “workflows” graphically, I rolled my own “ActionsEditor“.

Then Leopard introduced powerful new widgets that let third-party applications construct Automator workflows in the same way Automator.app does.

It just didn’t’ make sense anymore for me to maintain my own Automator knock-off, when I could use the real thing. And, the real thing requires Mac OS X 10.5.

Another benefit of using Automator, now people can use special actions that IMLocation can do (e.g. disabling built-in speakers) in their own workflows.

Support and Quality Assurance

Writing code that runs on two operating systems obviously means more work, and that’s a reason for dropping Tiger support. But a bigger problem I had was quality assurance.

Since I don’t have dedicated testers, I have a lot of trouble doing enough testing of things I don’t use day-to-day. It’s not something I’m satisfied with, but it’s something I have to accept, given my resources.

I only have one computer and it runs Leopard. I don’t think I can do the necessary quality assurance to be confidant that things work on Tiger, because I don’t spend enough time in it.

Only needing to test one operating system means, I can ship with fewer bugs.

New and Improved

Leopard also introduced several technologies, like Objective-C 2.0, that are a big help to programmers, but can only run on 10.5. My hope is that by using them, I can deliver a more useful and stable product faster.

Personal Reasons

Now, here, you see, it takes all the running you can do, to keep in the same place. If you want to get somewhere else, you must run at least twice as fast as that!

The Red Queen

Technology has a shelf-life, and a learning curve. To stay on top of things I need to move.

Time to Learn

A new programming technology is usually bundled with a whole new way to do software engineering. For example, you need to know what Object Oriented Programming is to get the most out of C++, and even if you grok C++, you have to understand what “message passing” implies to get the most out of Objective-C. Just writing code the same way you always did in a new language won’t cut it, you need to experiment, and try new things. But that takes time.

Writing code that only runs on Leopard gives me the time to actually practice programming with newer technology. There’s no substitute for writing code.

Garbage Collection

It took me a long time to finally understand memory management in Objective-C; it was one of the biggest stumbling blocks to writing good Objective-C code. And then Leopard introduced garbage collection (GC), which is a whole new way of (not) doing memory management.

GC promises to make writing code much easier. But in my experience, when you have an issue with memory in a GC-ed system, it’s much more … esoteric … to understand and fix. It’s a poster-child for “there’s no substitute for experience”.

the iElephant in the Room

To write code for the iPhone, you really should understand Objective-C 2.0 — the iPhone’s frameworks use it heavily.

Transitions IMLocation to Objective-C 2.0 is much better practice for iPhone programming then writing Objective-C 1.0 code that is compatible with Tiger.

Messages to Nowhere

January 3, 2008

This article has been updated, and moved here

NSWindow setResizable:

December 18, 2007

This article has been updated moved to a new location.

What Quality Means

December 18, 2007

I was blown away when I read the first part of this talk given by Joel Spolsky at Yale, because it so totally nails problems I’ve seen at Microsoft and problems at my alma mater.

I was also reminded of Will Shipley’s excellent article on the limitations of unit-testing.

NSWorkspace Bug in – openFile: ?

December 7, 2007

EDITED TO ADD: I could reproduce this bug in a large project, but not isolate it in a smaller one. It is much likely for my code to have a bug then NSWorkspace. I’m still not 100% certain that this issue wasn’t my fault in some way I don’t understand. But no matter what caused the bug, the work-around I describe here has been working for me. Please let me know if you have this same issue as well, or any insight into what I could have done to cause it.

The Problem:
I need to launch a background-application from inside the application-support directory. The OS is Mac OS X 10.5.1 build 9B18.
[[NSWorkspace sharedWorkspace] openFile:path];
where path is the correct path to the application, in my case “/Users/user/Library/Application Support/IMLocation/IMLocationHelper.app.”, works about 3 out out 4 times, but intermittently fails. It also reports success without actually launching IMLocationHelper.app, but this is far more rare.

Details:
When openFile: explicitly fails, it prints, “LSOpenFromURLSpec() returned -600 for application (null) path /Users/user/Library/Application Support/IMLocation/IMLocationHelper.app.” to stderr.

Error -600 is procNotFound /*no eligible process with specified descriptor*/.

The path is correct, the application exists there. I verified this by
assert([[NSFileManager defaultManager] fileExistsAtPath:path]);
before calling openFile:.

Calling openFile: again immediately after a failure often works

Also, while(![[NSWorkspace sharedWorkspace] openFile:path]);
will terminate, meaning it reported success at some point, but it will not always have actually launched the application at path.

(EDITED TO ADD: At first I thought that, NSWorkspace was probably opening IMLocationHelper, but not blocking until it has finished being launched. But sleeping, to give IMLocationHelper time to finish launching, did not solve the problem.)

performSelectorOnMainThread did not solve anything ether.

I verify that IMLocationHelper has been launched by
assert([[ShellTask executeShellCommandSynchronously:@"ps -axww | grep IMLocationHelper | grep -v grep"] length] > 0);

A Workaround:
[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:[NSArray arrayWithObject:path] waitUntilExit];.

This calls the open command to launch the application. I have not been able to make it fail when path exists.

Crash Logs

December 7, 2007

Daniel Jalkut on how to get the most out of crash logs. It’s good advice.

Actually I do have one big issue with the article:

If there’s one behavior of your application that you should focus on eliminating, it’s the behavior of crashing. Above all other “nuisances,” this is the one that is absolutely unacceptable.

But preserving someone’s data is more important then crashing. Having to rewrite your paper because your PC devoured it is worse then crashing. Crashing may be the worst “nuisance”, but there are more important bugs to squash first. However that is a topic for another time — we all agree that crashes are a problem should be fixed.

Although Daniel shows how to synthesize debugging symbols from hex-address, I think it’s worth considering leaving debugging symbols in your shipping app.

The reasons for [building applications without debugging symbols] are mostly to keep the shipping application as small as possible, but there are also some good reasons to hide the symbols if they reveal too much about your business strategy.

I can’t say anything about your business strategies, but removing information that can help you diagnose problems “in the field” seems like a very bad trade-off for slightly smaller files.

Hard-drives cost about $0.30 per gigabyte (GB), and the price is still falling fast*. Because the GB is the unit hard-disks are sold by, I am going to use it instead of MB or KB; I think it puts file-sizes into the right perspective.

Today’s applications are “big”, for a very good reason. That article says it better then I can, but the gist of it is that megabytes are cheaper then air and bigger programs can do more, making them more useful (the cost of a GB of storage space has fallen over 20 fold since the article was written, by the way).

The largest program I use every day that was built with debugging symbols on is EyeTV. It weighs in under 0.11 GB, and I don’t consider that “bloated”, because I get good value for my 3 cents of disk-space. Stripping debugging symbols with strip makes it 0.0076 GB smaller. That translates into $0.002 worth of hard disk, that could store 13.7 seconds of TV . And that is insignificant. A few thousandths of a GB make little difference, and that’s all stripping debugging symbols will get you.

Of course, this is all academic if no one ever sees the crash-logs. Unfortunately, developers know, that’s the current crappy state of affairs. Crash reports are sent to Apple, and only Apple. The developers who wrote the program — the ones who could best fix the problem, and who desperately want to know about it, are completely out of the loop.

If Apple passed crash logs on to developers, everyone would win. Developers would be able to squash more bugs in less time. Users would have a better, more productive and bug free, experience. Apple could sell those improvements. Microsoft already does this, and it seems to work well for them. Most people are unaware of this SNAFU, and probably think that reporting the crash to Apple gets the information to the right people. I don’t know if educating people about the issue would light a fire under Apple, but it might.

—-

If enough people start using flash memory over current magnetic-platter harddrives, then the price-per-GB ratio could change, because flash is currently about 100x more expensive (per GB). But the trend of the current storage-medium’s price exponentially falling will continue

Flash-based notebooks are already here, but they aren’t popular, yet.

But by the time flash-based computers become popular, their cost-per-GB will probably be as good, or better, then full-sized hard drives of today. Tiny hard-drives, using conventional magnetic platters, like the ones in the iPod, are also a compelling alternative to flash.