Tuesday, September 11, 2012

Worse Development Anti-Pattern I've Ever Seen: Using Goto in Objective-C

This is actual code I was reviewing a few months ago. I've anonymized the code and did a bit of renaming... 
- (BOOL)aTerribleMethod:(NSString *)iDontKnowWhatImDoing
{
    if(iDontKnowWhatImDoing isEqualToString:@"YES") {
        [self callAnotherTerribleMethod];
        goto bail;
    }

    if(iDontKnowWhatImDoing isEqualToString:@"SOMETIMES") {
        [self callYetAnotherTerribleMethod];
        goto bail;
    }

    if(iDontKnowWhatImDoing isEqualToString:@"NO") {
        goto bail;
    }

    //Do a whole bunch of other stuff

    bail:
}
If you've ever written something like this, please quit programming.

Monday, September 10, 2012

LLDB Custom Object Summaries Implemented Using Python, not Objective-C

In the seemingly benignly titled WWDC 2012 session Debugging in Xcode, the speaker team shows you how to implement custom summaries on your own objects for LLDB. This is pretty important since LLDB is now the recommended default debugger as of Xcode 4.3 (Xcode 4.4.1 is the latest at the time of this writing, with Xcode 4.5 just days away).

What a second, what's wrong with implementing [ClassInstance description]? The speaker sternly says it's an action fraught with danger since you might run code and change the state of the object inside description. I admit, I never really thought about it much. But one of the side affects calling description caused was seeing the dreaded Summary Unavailable next to your variable where its description should be. When implementing LLDB, Apple choose another way to get custom summaries which really surprised me.

For LLDB, you create a Python script that directly inspects member variables of your class, then you use Python code to do any summarization, formatting, or transformation, and finally return a Python string. The video shows exactly how this works, and of course you need to register a script and function in the script to call when LLDB sees your Objective-C class.

I'd never seen Python before. It doesn't look radically hard to pick up, and seeing it used for LLDB sure made me wonder if it will have a more prominent role at Apple in the future. Things that make you go hmmmm…

Friday, September 07, 2012

My Favorite Unadvertised OS X 10.8 Mountain Lion Feature

Notification Center is without a doubt my favorite Mountain Lion feature, particularly the way Calendar reminders go from moderately disruptive to not disruptive at all.

My favorite unadvertised feature is that you can now add files to the Trash while it's emptying! I know, it's the kind of thing that seems like a no-brainer/should have been there for years, but it wasn't.

This is great for me since emptying build folders, or large batches of icons takes a few seconds, and I frequently find something else to trash after I've already started emptying the trash.

Wednesday, August 22, 2012

Is Amazon Glacier Really As Cheap As It Seems? The Math Might Be Surprising

I was very excited to read the announcement of Amazon Glacier earlier today and signed up when I had a few minutes last night.

NewImage
At first, it seems perfect. $0.01 US per GB / month seems crazy cheap. I love the idea of only paying for what you use, look at that table for potential storage costs.
How could you really go wrong at 100 GB for $1.00?
First thing that went wrong was I didn't know was there is no client! The only way to get data into Glacier is via API calls. I'm sure that existing clients that support S3 will adapt to include Glacier support as well, it's early days.
I thought about rolling my own, but Amazon has Glacier SDKs for Java and .NET, so no quick OS X app could be cobbled together to get my data in. I mean I work with REST APIs all day long, and Glacier has that too, but I wasn't looking of that kind of work last night.
While doing a last ditch search for a client that already supported Glacier, I stumbled on the Hacker News post Beware that retrieval fee! I hadn't paid much attention to the retrieval fees when I activated my account. I'm thinking of Glacier as an emergency, the house burned down, kind of retrieval situation. So how much would that scenario cost?
That's where things get…complicated. How can Amazon offer a storage service and not provide a calculator or spreadsheet that helps customers estimate their costs? Seems like Amazon is hiding the true retrieval costs because, well, look at the math I came up with.

NewImage





















If my math is right, those download costs sure add up quick. Calculating this stuff appears intentionally very tricky. The Paid Retrieval columns represent my best guess based on the information I found, but I could totally be wrong. I tried to use the Glacier FAQ Formulas to work it out, but its crazy complicated and written mostly as prose! After I did the formulas one way I thought could be right, I re-read all the discussion and theories on formulas on the Hacker News thread, then found this Wired article. In the Update section, Amazon lays out a completely other formula for the Billable Peak column if you're downloading your whole archive. I used that because it was easier and I think it fits the scenario I'm looking for better, which is immediate disaster recovery. If you've lost everything, you don't want to trickle download your archive to stay under the GBs / hour column.
If you want to play with the math yourself, you can use the spreadsheet I started with:

Amazon Glacier Pricing Math - Numbers
Amazon Glacier Pricing Math - Excel

Sunday, August 19, 2012

Watch: Keanu Reeves shares some insights on the digital vs film debate in Side By Side

How come Keanu Reeves sound so much smarter here than in anything else I've seen him in?

http://www.hitfix.com/motion-captured/watch-keanu-reeves-shares-some-insights-on-the-digital-vs-video-debate-in-side-by-side

Own Your Words

Scott Hanselman says Your Words Are Wasted. If you don't have a blog, get one. If you do, start posting more. Figure out how to make posting on your blog as easy as posting on Twitter, then you win!

Friday, August 10, 2012

Of Course I Would Get Punished The One Time I Buy Music from Amazon

I hardly ever buy music from Amazon, I'm always afraid somethings going to go wrong because of course it's happened before.
I had some MP3 download credits through movie ticket purchases, so I finally decide to spend them and this:
Screen Shot 2012 08 09 at 10 55 06 PM







I was literally toggling back and forth between iTunes and Safari, thinking do I pull the trigger with Amazon or pay out of pocket with iTunes because I know it's going to work, there's just about no risk.
WTF do I do now? In no way do I want to contact f***ing customer service to buy an album.
Instead I find the link to Your Cloud Player under the Account menu, find the album, attempt a download, have to install the downloader, get told a download failed repeatedly for a song bought like a year ago, and finally the download for this purchase succeeds, but still says some imports failed for the old song. I have iTunes Match, so I then go into iTunes, wait for matching to complete, then delete all the songs and download from iCloud to get AAC files.
Simple.

Monday, July 30, 2012

I've Been Charging iPads Wrong For Over Two Years

MB352
I've got a number of these iPhone USB Power Adapters lying around the house. When I got the iPad 2, I knew of the higher power requirements for charging, but I just never thought much about it because I usually charged the iPad by plugging it into my iMac.

iOS 5 & iCloud changed all that. With backups now going to iCloud, I really had no reason to plug the iPad into the iMac. So I started plugging the iPad directly into the wall, using the iPhone USB adapter. Was charging slow? When I paid attention, sure, but I usually didn't notice because I charged overnight.

When I got the iPad Retina, aka iPad 3 or the new iPad, I noticed charging took a long time. I mean a really long time. I rationalized this away because I know how much larger the iPad Retina battery is. But I started to kind of plan around having to charge the new iPad, making sure the battery was topped up if I knew I needed to use it for an extended time on battery.

I don't remember who, or how it came up, but recently someone mentioned you have to be using the iPad 2+ included adapter or charging takes forever. I of course dismissed this out of hand. How could I, with all the iDevices, detailed knowledge of the development platform and hardware, possibly not be using the correct adapter? I certainly didn't remember any fancy adapter!

21OytorvA3L
Yesterday I opened the iPad 2 and iPad Retina boxes, and sure enough, there's a 10W USB Adapter included! I immediately took my 50% charged iPad Retina and plugged it into the 10W adapter. A few hours later, 85% charged, BOOM! That is simply astonishing charging speed compared to what I was seeing before.

Best of all, the 10W charger works with all iDevices for the fastest charging possible. The cherry on top is that the 10W has a removable plug so you can use it with the World Travel Adapter Kit or the US extension cable.

I was feeling super dumb when I saw the 10W adapter in the iPad boxes, but I quickly got that once I realized how much an improvement this was. If you never took your 10W adapter out of your iPad's box, now would be the time.

Update
While doing laundry this morning, I saw the iPad 1 box, which has been demoted to the basement. I wondered what charger was included with the iPad 1 ? Was it the iPhone Adapter? Opening it up, I see the box layout is the same as the iPad 2 and new iPad, but a charger wasn't in the box! I went back up to the office and opened my junk electronics drawer. Sure enough, another 10W adapter was there collecting dust. I obviously completely forgot about it when I moved houses late last year.

Feel like I should be busted to Apple geek private or something.

Monday, July 16, 2012

License Agreement Screens in Mobile Apps are a Really Bad Idea

Launched the latest update to The Weather Channel app and this is what I see:
IMG 0832
License agreements in apps are a terrible idea. The only app I've ever seen implement something like this is the iTunes app, and that has widely been derided as terrible user experience.
I know I've never seen this on a web site, I'm sure weather.com will never show a license agreement before showing the front page. Why should the app be different?
Worse, the App Store already includes a provision for license agreements, and custom ones at that. Every app gets a generic license agreement that Apple has written by default. However, if you want to provide a custom one, you can.
In the App Store page for The Weather Channel app, I've highlighted the relevant link.
★✩✩✩✩
Screen Shot 2012 07 15 at 12 49 38 PM

Monday, July 02, 2012

Sometimes it's the little things in programming that surprise the most

I need to brush up on Core Data, I've got bugs to solve and I haven't used Core Data for anything real yet, so best to school myself.

I've got iOS Programming: The Big Nerd Ranch Guide 2nd Edition with a chapter on Core Data and Core Data: Apple's API for Persisting Data on Mac OS X to choose from to get started. I chose iOS Programming because it's just a chapter, should be more focused if I can't get all the way through Core Data…

I'm reading through, getting reacquainted with the terminology when I see something that strikes me as odd. The sample is talking about how entities in Core Data don't automatically save their order relative to other entities and how you have to create an attribute yourself to manage this. Authors Joe Conway and Aaron Hillegass call it orderValue. No big deal, done this countless times. Then the authors do something completely unexpected. Instead of using an integer for the attribute, they use a double!

I literally think "huh, that seems strange, I've always used an integer..." and keep reading. A few paragraphs later, they explain why they chose a double. If the entity's position is changed, with an integer you have to change all the other entities orderValues. With a double, you just find the orderValue of entities in front and behind the entity that got moved, then add them together, and divide by two. Thus, the new orderingValue will fall directly in between... As soon as I read that, my mind did something very similar to this moment in Pixar's Ratatouille when critic Anton Ego has a childhood flashback after trying the titular food (starts at :15 into the clip).

 Of course instead of food, I flash backed to all the code I ever wrote using an integer to solve that problem. Correction, all the wrong code I wrote to solve that problem.