Software typos

Today as I was happily working in Apple’s Interface Builder working on some software, an error message came up that made me laugh. You can definitely tell that it never got proofread as it refers to a “header filer” instead of a header file. For your amusement, here’s the error:

Picture 1.png

Drawing conclusions in bug reports

When I was become an EMT (Emergency Medical Technician), we were taught to observe and report without making a diagnosis, because we were not trained to do so. This concept also applies to bug reports. Over the years I’ve seen users/customers report bugs and attempt to say why the bug is happening. Unfortunately, many times the user is completely wrong. Without seeing the source code, knowing how things work, and/or not knowing a particular standard, it is nearly impossible to draw a conclusion as to why a problem is happening. I wish that bug reports would do what I was trained to do becoming an EMT; observe and report. Let the developers make the conclusions and fix the issue.

Stupid Bug

The other day as I was tracking down a bug, I almost kicked myself when I saw the problem. The code was something like:

int i = 0;
int count = [array count];
for (i = 0; i < count; i++)
{
	if ([[array objectAtIndex:i] intValue] == 3)
	{
		[array removeObjectAtIndex:i];
	}
}

The problem with this code, if you’re a Cocoa programmer, should be obvious. If any of the elements are equal to 3, then when you get to the last or near the last element, there are no objects left in the array and it blows up. The proper way to do this, of course is:

int i = 0;
int count = [array count];
for (i = count - 1; i >= 0; i++)
{
	if ([[array objectAtIndex:i] intValue] == 3)
	{
		[array removeObjectAtIndex:i];
	}
}

By counting down instead of counting up, the problem is solved. What annoys me about this code I wrote is that I’ve done something similar many times. You’d think I’d learn by now.

Is it hard to polish software?

I’ve been using Parallels for a few weeks now running Windows XP and am amazed at how well it works. In the latest release candidate, they’ve cleaned up a bunch of things, but stil seem to be missing some very obvious user interface issues, most likely caused by the cross platform libraries they’re using or something like that. If you look at the screenshot below you can see that the popup button definitely doesn’t look right.

UI.png

Is it so hard to fix this? I hope that it’s cleaned up for the final release. Furthermore, the popup isn’t a true popup button. Popups in OS X show the menu in line with the button. The image below clearly shows that this isn’t a true popup button.

UI2.png

I think that the engineers working on Parallels are stellar at doing the low level stuff, but it looks like they need a bit of help with the user interface. (I’m available for contract work, if they need help :-)).

Sync Services can make a mess and here’s a way to clean it (maybe)

I think that Apple’s Sync Services is an excellent technology and has a lot of potential. It is not quite mature, but I have high hopes for it in the future. One of the problems that has been brought up on the Sync Services developer mailing list is that there is no good way for an end user to remove data from Sync Services and unregister it if they remove a program. All developers are in the same boat and Bare Bones, developers of the popular Yojimbo that I’ve blogged about have written a FAQ about it for their product. Unfortunately this really isn’t a solution, especially for people that want to keep clean systems.

This morning, I decided to attempt to write up a solution to this issue. While my attempt doesn’t solve everything (it only unregisters items from Sync Services and doesn’t actually remove the data from Sync Services or .Mac), I’ve decided to put it out there and include the source code. The app has been lightly tested and may cause issues on your system, so only use it if you know what you’re doing. By downloading this, you take full responsibility for using it and if it nukes your data, I’m sorry, but there is nothing I can do. Having said that, make sure you have a backup first and good luck. This app uses undocumented Apple calls and is likely to break sometime in the future.

You can download my creation here. It’s quite small, so don’t be surprised if it downloads almost instantly.

The application and source code are free to use and modify. While I’d appreciate some feedback on if it helps, there is no requirement to do so.

Is my job easy?

I sure hope my job isn’t easy, because if it was, I’m definitely doing something wrong because it isn’t easy for me. Over the years, I’ve heard people say that other jobs are easy or are hard without ever experiencing them. Take teaching, for example, outsiders think that teachers get it easy with summers off and leave school around 2:30 pm or so. What they don’t see is teachers getting up at 6:15 am, staying at school until 4 pm and then coming home and doing lesson planning for awhile (at least the dedicated ones). Do I know what it is like to be a teacher? Not really, I’ve given a few lectures for my local CERT, taught CPR and First Aid in college, but I really don’t know what it is like to be a teacher day in and day out. However, my experiences have shown me that it is damn hard to prepare for a simple lecture and can’t imagine what it is like to prepare for 5 classes a day.

What about my job? Well, as I say, if it was easy, everyone would be doing it. There are some “easy” parts of my job, but they don’t last long because easy usually means done quickly so they’re over and done with in the blink of an eye. Some people think that a feature or a design is easy just because some other application may have implemented it. Do I have any idea how long someone else spent implementing something? A feature may look simple on the surface, but the time and effort implementing a feature could be huge.

If I ever say that someone else’s job is easy (and I haven’t done that job myself), I need to remind myself that I need to be slapped.

Standing on my head debugging code

This weekend I was looking at optimizing a program I’m working on and tracked down high CPU using to NSProgressIndicator which shows progress, obviously. The CPU usage has to do with animating it. After hours tracking it down, it turns out I was calling [NSUserDefaults resetStandardUserDefaults] at the beginning of my app. I have no idea what one has to do with another, but I wasn’t 100% convinced of this until this morning when I reproduced the issue with a bare bones test application. I submitted a bug to Apple; this really explains some slow downs with OS X. Amazing that the pretty pulsating progress indicator can slow down a machine so much. Uggh.

I love programming

It must be a good day in my world as I can say that I really enjoy what I’m working on right now. I’m working on some brand new code where I pretty much get to make all the decisions and there are no outside dependencies. Almost every project I’ve ever worked on has relied on something, starting with NotifyMail required server configuration, to my handheld work that required code to work with third parties that I can’t control. Having full control over my code (with the exception of maybe Apple bugs which I haven’t encountered any with my current stuff) makes it so much more enjoyable to do my job. While there are still tricky parts to my code, they can be solved without too much effort. This isn’t to say what I’m doing is easy (I still code in my sleep). I’m sure I’ll move on to something that I can’t control real soon, but for now I’m going to enjoy what I’m doing.

Fun with Pointers (not the dogs)

One of the aspects of programming that took me a long time to understand was (memory) pointers. I grew up with BASIC, learned Pascal and C where I always used fixed length structures or types and never cared about memory allocation as it was way too confusing to me. In college, I majored in engineering and only took 1 computer science class, so most of my programming knowledge is self-taught, on the job training. It wasn’t until a few years out of college that how pointers worked really clicked. These days, with high level frameworks and languages such as Objective-C and Cocoa, I don’t use pointers all that often (I still have to deal with allocation and de-allocation of memory), but when I need to use them, they’re a piece of cake to use. I find that I only use them when shipping data across a wire, i.e. to/from a handheld device. Knowing how to use pointers, walk pointers, etc. makes complicated code very easy. I think that understanding how pointers work is essential to being able to write applications that aren’t self-contained, i.e. only run on a desktop machine. I wish I had learned about them earlier as I’m sure it would have made my life easier.

Sample code is great (when it works)

I think that it’s great that companies like Apple put out sample code to help developers write code without having to resort to figuring it out themselves or doing something in a way that will break. Several years ago I wanted to add my application (NotifyMail) to the login items/startup items for a user under OS X when OS X was new. There was no documented way to do this, but a DTS engineer at Apple posted on a mailing list that if people wanted code, to send him email. So I sent him email and have been using the code ever since in a bunch of projects. It had a major limitation in that if System Preferences was open and you used the code to modify login items, the user wouldn’t see the change which could be confusing. I had added an awkwardly worded alert indicating this and no one complained.

As I was changing some setup stuff on one of my machines, I added an item to the login items by using the contextual menu item in the dock. I then opened up system preferences and began adding and removing it via the menu again. To my surprise (and delight) system preferences immediately indicated the change. After a bit of searching, I found some sample code called LoginItemsAE which was first created last October. I download the code, added it to my project and attempted to compile. Hmmm…it relied on stuff in Mac OS X 10.4, but I was targeting 10.3 (and 10.4.), so it didn’t compile. I double checked the sample code and it says it goes back to 10.2. After a lot of research, it turns out that in order to get the code to compile, even if targeting 10.3, I had to set the SDK to the 10.4 SDK. I didn’t want to do this as I have 50+ targets in one project that all use one configuration file that sets the SDK to 10.3.9; this kind of change could be bad as it would allow me to use functions only found in newer OS versions and then crash on older systems. So if I’m not careful, I’ll get a crash. By setting the SDK, if it doesn’t compile, it won’t run on the older OS version which makes life easier. It would be nice if there was a way to warn you about which functions aren’t available on newer OS versions.

To make a long story a little shorter, I had to whip up some stub code to get it to compile which was a whole lot more work than I had expected.