Murder me!


I’m spending too much time trying to figure out how to assert that a string is properly URL encoded! I refuse to take the traditional approach of running code in the application and peeking through debugger goggles or some obscure log output. Unit tests are made for this sorta thing! I’e had some tips that suggest how to perform URL encoding but experience teaches me not to trust any particular tip unless I can confirm it in a learning unit test. That’s how I self-educated myself on Ruby over the weekend. I wrote a bunch of learning tests to confirm every code snippet I read online. So why is it that when I assert @”ab%%c” == @”ab c” the error message echoes back “ab != ab c”??? I’m using Google tools for Mac to run iPhone unit test suites.

One other thing… could somebody please invent/has somebody invented an “automatic add new files to svn” plugin for XCode? If I botch one more commit my team is going to cut off my water supply and replace my contact lens solution with Windsor’s clear hot sauce. I love the clear stuff because I can dump a whole bunch on my meal without my wife nagging me about my heartburn.

Objective C, Almost closures?


I’m about toe deep in ObjC and Cocoa and I’m starting to get that warm fuzzy feeling everytime I message and object without needing a type cast. I get really warm/fuzzy when I use @selector() to throw extra executable logic from a long running process back onto the main thread. Now I’m thinking about the @selector idea and wondering how close it is to closures. I’d like to be able to define a method on an interface… *ahem* …protocol that takes a selector as a form of callback. Though Cocoa makes extensive use of delegates I don’t want to haff to set a delegate instance variable and define another protocol for something as simple as an inlined callback operation. In other words I wanna say: “Mr. Object, do dis stuff when your data becomes available.” Back into the manuals to learn about @selectors.

The phone’s ringing but nobody’s home


You know what I like about Objective C? When you send a message to nil. You know what I hate about objective C? The phone ring’s but nobody’s home. Think about this a minute. Imagine if you were to dial your loved one and mistake a “4” for a “5”. The house you dial has no answering machine/service/secretary. You have no definite way of knowing that you dialed the wrong number or that nobody’s is there. All you know is that you always call at exactly 12:15pm during lunch after taking the 5th bite of your usual Chicken Cordon Bleu sandwich which you order daily from the same fast food provider (paid for by pulling what appears to be the same $10 bill creased in exactly the same corner out of your trusty tattered wallet then after reaching the door doubling back as you always do because you left your keys on the counter). You know your loved one always answers on the second ring and has no reason/desire/ability to suddenly dodge your usual 12:15, “How’s your day going? No, how’s YOUR day going sweetie?” exchange. You hit redial a few times to the same non-response and rather than accept the obvious fact you begin to panic. Something must be wrong! You verify every other point of failure except for the most obvious, calling other family/friends, contacting your building admin (y’all did pay the bill right?), even going as far as arguing with your communications provider(s) in a frantic attempt to resolve an inconsistency or ripple in your otherwise pathetically inevitable daily episode. (You were born with a slight undiagnosed touch of autism which not only hobbles you with predictability and inability to handle subtle changes in your routine but gives you a certain advantage in the field of software design which is roughly 90% about patterns.) After becoming Ralph Tresvant (featured in the clip below) and losing to the unlimited powers of the Verizon network (how come they always get over?) it dawns on you to finally attempt manually punching the memorized phone number into the keypad after which you finally get your much anticipated response, “How’s your day going?”

That’s kinda a little bit sorta like how I might have felt today after I spent 2 hours, 37 minutes and 17 seconds chasing an error where I forgot to set an instance variable in my Objective C class. A creature of habit, I like my runtime to yell at me when I access a null pointer! I love the freedom from these ambiguous errors but hate the flip side. You can go on willy nilly sending all kinds of messages to null pointers, non-objects, empty stuff and not know until three months after you’ve been workforce-reduced after slipping 5 months past a dead line while you spent 4 months and 28 days chasing a production day behavior oddity that just seemed impossible.

Bill Dudney said something like, “It’s not the learning curve that hurts it’s the unlearning curve” and I totally agree. I love/hate Objective-C and I could spit bullets at Steve Jobs for his take on Java and the arrogance of insisting his favorite programming toy should be everyone’s favorite programming toy. As much as I hated picking up yet another language/framework/way-to-do-things I forced myself on because to get hung up in any one tool-set or programming paradigm is to slowly reduce yourself to a collection of the basic carbons and minerals that make jelly-fish wiggle in the ocean. Lesson learned overall. Now I stand as I speak, “My name is Cliff, and I made a call to an empty residence.”

Titles, Strings, and Threads


I just got bit by a subtle Objective C bug. I’m writing a basic application that starts an asynchronous counter that updates an onscreen label. Common sense would suggest pseudo-code like this:

onButtonPress:
   if button title = "Start"
      set button title = "Stop"
      startBackgroundCounter
   else
      stopBackgroundCounter
      set button title = "Start"
end onButtonPress

The problem is this. The UIButton class in Cocoa has a read only currentTitle property. There’s no writing to this property however you can write to setTitleForState and pass a UIControlStateNormal enum. (Why do I hate enums?) So I’m thinking it’s enough to query the currentTitle property and then set the title for the normal state from “Start” to “Stop”, right? Wrong! Somehow the currentTitle property hangs onto the original value and instead I should be querying the titleForState: method instead! Can you tell I’m missing the JDK?