I've been thinking...

Static Typing is Safe Typing

Filed Under: Programming, Objective-C, Static Typing and Rants

Okay, I’m gonna come right out and say it: I love static typing.
I don’t know why; I just have always really liked it. Maybe I wasn’t tucked in enough at night, and now I need the compiler to do it for me. Or maybe it’s a mild form of OCD that only comes out when I don’t have compile-time assurances of correct data types. I really can’t explain it.

Anyway, because of this, I get really irked when I hear (let’s be honest, read) people say that my beautiful, glorious Objective-C is a *shudder* dynamically-typed language. They go on and on about how they’ve been freed from the shackles of… something 1 and how they can now code 300% faster and not worry at all about accidentally assigning an NSString to an NSArray variable because they never make mistakes anyway.

wut

It is indeed true that Objective-C can, if you’re a terrible person, be dynamically-typed. Rather than declaring your variables as, oh… I don’t know, what they actually are, you can declare them as type ’id’, which is compiler slang for “how do I computer?”. For example,

NSArray* array = [NSArray arrayWithObjects:@"String 1", @"String 2", @"String 3", nil];
[array floatValue];

would produce a compile-time warning (“‘NSArray’ may not respond to ‘-floatValue’”).
On the other hand, you could write

id array = [NSArray arrayWithObjects:@"String 1", @"String 2", @"String 3", nil];
[array floatValue];

and there would be no warnings at compile-time; just exceptions at run-time.

What I’m getting at here is that I don’t understand why someone would want to use Objective-C as a dynamically-typed language — it benefits you nothing and costs you not only safety, but my respect as well. Doing this saves a very small amount of time, perhaps (though I suspect the savings is so minute as to be almost immeasurable) and increases the chances of something going wrong in your code.

There are, not surprisingly, some valid use cases for Objective-C’s dynamic typing abilities; the most notable of which is pretty much the only way to distribute a single binary for multiple versions of a framework (such as UIKit).
Versions of iOS prior to 3.2 (which was released with the iPad) don’t include support for UIPopoverController (which is an iPad-only interface element). In order to maintain binary compatibility with older versions of iOS and use UIPopoverController on devices that support it, the crafty developer does the following:

Class UIPopoverControllerClass = NSClassFromString(@"UIPopoverController");
id popoverController = [[[UIPopoverControllerClass alloc] initWithContentViewController:someController] autorelease];
[popoverController stuff];

Never actually referencing UIPopoverController prevents the application from crashing when loaded by an old version of iOS.

I can’t think of another valid use of typing a variable as ’id’.

1I assume they've been freed from having to actually know what they're doing.

-Aaron


08/19/11 at 03:47 Universal
 

[Apple releaseInaccurateSDK]

Filed Under: Programming, Objective-C, Apple, iPhone and SDK

(I hate to reüse a gag for the title, but it seemed so appropriate.)

In preparing an application for release into the App Store, I figured it’d be nice for me to make sure my dynamic image resources would render with the appropriate amount of retina-bending power on iPhone 4 (after all, those people payed at least $200 for their phones; I figured the least I could do was allow them the privilege of getting the most out of their displays). I checked Apple’s documentation on how to support high-resolution screens, and it said that if I creäted appropriately resized (doubled) versions of my images and inserted the suffix “@2x” before the extension, both -UIImage initWithContentsOfFile: and +UIImage imageWithContentsOfFile: would automatically detect the higher resolution files and use them when needed.

Wouldn’t that have been fantastic?

No matter what I did, the high-resolution images were never loaded on any device or simulator. After 90ish minutes of trying and googling it, I stumbled upon Michael Tyson’s fix for the problem, which is a clever categorical extension that implements methods which for the existence of the properly suffixed files (like Apple’s methods are supposed to) and uses them instead (like Apple’s methods are supposed to).
Problem solved. Stupidly.

-Aaron


07/11/10 at 05:24 Universal
 

[Apple epicFailWithOrganizer:YES]

Filed Under: Programming, Xcode and Images

I was putzing around with Xcode the other day (well, I mean, I was actually accomplishing a goal, not just mindlessly pushing buttons, but I digress) when I ran across this… interesting error message in Organizer.

Alt Text

I had installed an app I was testing on my iPhone, deleted it using the phone’s interface, and, upon seeing that Organizer still listed it as installed, I tried to delete it using Organizer, too, yielding the above error.

I continue to be impressed by the clarity of the names that Apple chooses for things.

-Aaron


06/27/10 at 04:55 Universal
 

I Your Love

Filed Under: Glee, Music, Lyrics, French and Rants

I’m a loser. That’s a known quantity.
And I watch Glee. (Those two aren’t necessarily unrelated.)

So, I was watching an episode a few weeks ago (yeah, it takes that much mental effort to post something here) in which the Glee club performed Lady GaGa’s Bad Romance (which, by the way, is simultaneously dreadful and amazingly catchy), and I noticed an inconsistency.
In the original, Lady GaGa version, she says somewhere toward the end “Je veut ton amour” (which means “I want your love” (proving that she’s not as creätive as everyone says she is)). And I can even prove it (warning: that link is to the official music video; and it’s really freaky stuff. I suggest turning of your display immediately after clicking the link). Even though she kinda slurs “Je veut” together, she clearly says “Je veut ton amour”.

In the Glee version, however, the singer (who I think is the cute Asian chick, but I’m not sure) says (also very clearly) “Je ton amour”, which… although a very nice attempt, earns her only a bronze trophy for having-any-clue-what-she’s-saying-whatsoëver as it means “I your love”. Perhaps this was a way to make “Je veut” into one syllable… or… perhaps noöne involved in the music ever took French, but it bothered me.

I kinda feel better getting that off my chest, though. Thanks.

-Aaron


06/16/10 at 05:10 Universal
 

Work Online

Filed Under: Technology, Antifeatures, Firefox and Rants

In my many years on the series of tubes, I’ve never really had a use for the “Work Offline” feature found in pretty much every browser since 1995. Maybe I’m just different, but it doesn’t seem all that useful. Maybe in the early/mid-90s, if you’re reading an online newspaper (on your sleek and elegant craptop), and you have to go somewhere without internet access but still be able to read the paper, but then the problem is that you’re a dork. Who pulls out their (giant, at the time) notebook on a train or whatever just to read a paper? It just doesn’t seem all that useful to me

But I digress

Despite the proliferation of WiFi and cellular data plans and whatnot, Firefox still has this feature. “It’s not breaking your leg or picking your pocket” you may say. Well, you’re wrong, Tommy. It does break my leg nearly literally. Every fifth (or so) time I launch Firefox at school, it does this. It’s quite annoying.

So, my suggestion to the Mozilla people: kill “Work Offline”; it’s worthless.

-Aaron
/coolstorybro


05/12/10 at 19:05 Universal
Navigation
Panel