inessential by Brent Simmons

November 2010

OMG GC + modern runtime

Over the weekend I had the luxury of working on some code that is 10.6-and-up-only and runs only on 64-bit Intel processors. I turned on Garbage Collection and started using the synthesize-by-default and no-declared-ivars features of the modern runtime.

Holy shit it’s just too good. I love this. So much less code and less housekeeping. So nice. It makes it hard to go back this Monday morning to classic memory management and all the rest.

Treat Warnings as Broken Windows

The more years of programming experience I get, the more I like having my tools tell me about problems and potential problems.

Lately I’ve been switching my projects to use the same set of errors and warnings Peter Hosey uses.

I even turn on treat-warnings-as-errors — what Peter calls “hardass mode” — because, well, I want to be forced to stop and fix whatever it is.

(“Hardass mode” also simplifies my thinking: instead of two types of problems, there’s just one, and it has to be fixed right away. Any time you can simplify and thereby benefit, it’s good. We deal with plenty enough complexity already.)

Peter also mentions running the Static Analyzer, but I’ll reiterate that point. Do it. There’s a setting that will make it run every time you do a build (so you don’t have to explicitly choose Build and Analyze).

With one of my projects (so far, more to come) I’ve also been running unit tests with each build. The unit tests are in a separate project, which I made a dependent project in the app, so that the tests run every time. It’s another simplification: I don’t have to think about remembering to run my tests — they just run every time. Cool.

Bigger picture: Broken Windows

Six years ago, Daring Fireball published Broken Windows, a great post talking about operating systems and malware:

It’s similar to the “broken windows” theory of urban decay, which holds that if a single window is left unrepaired in a building, in fairly short order, the remaining windows in the building will be broken.

I think there’s something similar with writing software. Consider the following bit of code:

NSInteger arrayCount = [someArray count];

In the real world that’s pretty unlikely to cause a bug. But it’s wrong, because count returns NSUInteger rather than NSInteger. Big deal, right? Most bugs occur at a higher level than this. They’re logic bugs that error-checking can’t catch.

So is there a real point to fixing these things?

YES. Because it is wrong, and because there might be bugs lurking in there. And having any doubt at all is like having a broken window.

Being a hardass about the correctness of my code has had a great effect on my mental state when programming. Knowing that all windows are intact (and clean and shiny and transparent) makes me respect it more — and respect the software and my own abilities — and that’s very much to the benefit of the software, even if sometimes I find myself fixing picayune stuff that I know (that I think I know) would never cause a problem anyway.

I used to think sometimes: “Hey, I’m a professional of many years. I know what I’m doing. I can break this rule because I know for sure it will be fine.”

I don’t allow that thought anymore. Instead, now I think: “Hey, I’m a professional of many years. I know what I’m doing. I’m wise enough to use every tool at my disposal to make sure my code is correct.”

360 MacDev - last Mac conference before Mac App Store

I’m totally looking forward to the first 360 MacDev. I’ve been to every 360 iDev (iPhone/iPad) conference, and they’re fantastic conferences.

Unlike 360 iDev, MacDev is a single-track conference. The schedule starts with Mike Lee doing “Dirty Jokes and Code” — hopefully in his pirate suit — and includes speakers Justin Williams, Marcus Zarra, Dave Wiskus, Kyle Richter, Michael Simmons, and more. One of the topics I’m most interested in Saul Mora’s talk “MacRuby and You,” and of course things like networking, Core Data, UI design, and marketing are covered too.

It’s in downtown Denver this December. (My company NewsGator is in Denver, and I visit several times a year, and so I can assure you that we’ll not lack for entertainment in the evenings. Fun town.)

The big thing for me, though, is that the Mac developer community is about to change in a big way, with the Mac App Store opening soon. This is the last chance to get together before the change — it’s like seeing your favorite band right before they sign with a major record label. (Only we’re also the band.) I hope to see you there!

Discount code: Use Ranchero25 to get 25% off when registering.