Prometheus

I saw Prometheus in glorious IMAX 3D on opening weekend, and thoroughly enjoyed the film. It starts off with sweeping vistas of pristine landscapes, which look beautiful on the big IMAX screen. There were a lot of callbacks to the original Alien movie, most of them subtle. Some as simple as the Prometheus having a similar interior architecture and design as the Nostromo. Prometheus had scenes of futuristic sci-fi gadgetry, sequences of fast-pasted action, and a few horrifying and terrifying moments, and I enjoyed them all. I won’t say too much more about the content of the film, because I don’t want to give anything away for anyone who hasn’t yet seen the film.

Prometheus is a stark contrast to the Avengers, both in tone and content. The Avengers is a PG-13 fun comic book action movie that doesn’t take itself too seriously, while Prometheus is an R-rated epic science fiction film, with lots of imagery and dialog that is intentionally vague, so that after the film ends, the audience is left with plenty to discuss as they parse what they just saw and what it meant. Once the Avengers ended, although I enjoyed it very much, I simply left the theater and left the movie behind.

I had high expectations for Prometheus, and have been following a lot of the discussion on Twitter and the greater internet. Eventually I did stop to avoid spoilers as the premiere date approached. I even stopped reading Roger Ebert’s review because I felt it was getting too far into the plot. Now that I’ve seen the film, I am free to participate in the discourse and watch all things related to Prometheus. Prometheus definitely lived up to the hype in my opinion, and I will see it again as soon as I can.

Advertisements

The Art of Programming Without Programming

As I have been working on Debtor, my iOS app, I’ve come to realize that half of the work of programming is done away from the computer.

It’s a cycle, and it goes like this:

I spend many minutes, perhaps hours, coding and reviewing API documentation to build my application. I get stuck on a certain problem, and all the documentation, googling, and fiddling around in the code is not going to solve the issue. I need to stop and THINK.

So I step away from the computer, and go do something else.

While I am away, my programming problem is still there in the back of my mind, and if I’m not actively engaged in some other activity, I will go back and think of different ways I could possibly solve it. Meanwhile I’m in the shower, walking up the stairs, driving in my car, whatever. And then all of a sudden, a solution will come to me.

I can’t wait to get back to my computer to try out my proposed solution. Often times it is the correct solution, and I just needed time to process the problem in my mind before I could find a solution.

So if you find yourself stuck on an issue with your code, and you don’t know how to solve it, just walk away, find something else to do, and your brain will continue to process your problem, and solve it for you while you go about your daily business.

Concrete example:

Problem: I have a tableView with a textField inside each cell. I need to find a way to update the data source for my table with the data entered in the textField. How does the textField know which cell it is in? Do I have to keep a separate array around to keep track of the textFields? Should I just loop through the tableView cells when I really need the data later, or should I capture the data as the user enters it?

Solution: Go take a shower. In the shower, I remembered that each view can get an array of subviews, so there must be a way to get a superview of each view as well!

UIView * parentView = textField.superview;

This gets the parent view of the textField. Then cast the UIView to a UITableViewCell, which I know it is, because that is the only thing that has a textField in my class. The text field delegate method

-(void)textFieldDidEndEditing:(UITextField *)textField

is the perfect place to get the textField’s superview, because at that point the user is done editing the textField. I can grab the text in the textField at that time, and update the proper array element in the table’s data source. But then how do I get the array index that I need to update? From the UITableViewCell, which is the superview of the textField, I can get the index path from the table view by sending it the indexPathForCell:(UITableViewCell *)cell message. From the index path, I can get the row, and send the data source array the objectAtIndex:[indexPath row] message to get the correct entry in my data source array. Then I just update the data source with the textField.text, and my data and view are in sync!

Introducing Debtor for iOS!

Debtor on an iPhoneMy first iOS app, Debtor, is now available for free on the App Store! At this time it’s for iPhone only. View it in iTunes here.

I came up with the idea for Debtor when I was working on my household budget, and I wanted to calculate how much money I should set aside for credit card bills. The goal is always to pay them off as soon as possible- but how much can I save by paying them off sooner, and how much money does it really cost to pay off a balance of, for example, $5000? With an APR of 11%, and a monthly payment of $300, Debtor will calculate that you will pay $460.65 in interest, for a total of $5460.65.

This is just the beginning, version 1.0. I am currently working on an update, which will add features and fix bugs, so keep an eye out for that in the coming weeks.

Replacing the Battery in an iPhone 3G

My daughter’s hand-me-down iPhone 3G has had a bad battery for awhile, but it hasn’t been an issue until now, as we will be traveling this week. I have extensive experience opening up Apple computers and gadgets, going back as far as 2003 when I upgraded the hard drive in my white iBook G3 to a whopping 60 GB. The only time I ever opened up an iPhone before was once to replace the back panel of an iPhone 4. I’d never tinkered with the guts of an iPhone before, but since this was just an old iPhone 3G I figured it was low risk. This iPhone is really a spare anyway.

So I decided to replace the battery myself, and ordered a replacement battery from ifixit.com. It arrived in only a few days. I was excited to get started, so I didn’t bother reading the instructions before removing the two screws on the bottom of the iPhone. Then I already hit a wall and had to read the directions– I realized I didn’t know where the iPhone display separates from the bottom! After reviewing the directions, I read that the display is only the part of the phone inside the chrome bezel. Then I hit another stumbling block– how do I open the phone? Do I pry it open like my old 2nd gen iPod? Turns out I need a suction cup or duct tape to adhere to the screen so it can be pulled off. I really wish that information was more obvious, but I blame myself for not reading the instructions. I searched the apartment for about a half hour before I finally found something with a suction cup.

I used the plastic holder for a shaver in the shower to pull of the display, and it came off fairly easily. The risk in that step is if you pull too hard you might rip out the cables that connect the display to the logic board.

Once the iPhone was opened up, I followed the directions on ifixit.com to disconnect the tiny cables, remove the correct screws, and then pull out the logic board. Whenever there are lots of screws are being removed, it’s critically important to know where they go when it’s time to put them back in. For this project, I  laid all the screws off to the side, in a pattern matching where they came from, so they look like a connect the dots puzzle. Removing the battery was tricky because it is glued to the back of the phone. I just kept prying and wiggling until it came out. I made sure not to apply to much pressure with the spudger tool because I was concerned that it might snap under pressure, but it survived.

The new battery came with adhesive already applied to the back of it, so I just removed the 3M backing and carefully put the battery back into it’s snug little spot. Then I began the reassembly process, putting the logic board back into it’s spot, and screwing it in. The nice thing about reassembling the iPhone 3G is that every part has it’s place with no wiggle room, so it was obvious when the battery and logic board were back in place. The hardest component to put back in it’s place is cable #3, which just slides into it’s little spot on the logic board. All the cables snap into place except this one. I used a tweezer to push it back in because it was not possible to do with my fingers. Once all the cables were in place, I decided to test it out and turn on the phone to check that everything works before closing up the case. Just then I decided to help my wife out and hold my 4-month-old baby so she could do whatever she needed to get done at that time. I plugged in the phone because I didn’t know if the battery would have a charge. I powered on the phone, and the touch screen and everything was working, and then all of a sudden the baby I was carrying grabbed the iPhone power cord and sent the phone flying to the ground, and the screen was pulled off! So I put my son down, and worked for another 20 minutes getting that pesky #3 cable in it’s spot and test everything and promptly completed the reassembly once I saw that the screen worked as it should. I wonder how the iPhone software deals with the screen disconnecting while it’s powered on?

Replacing the battery on the iPhone 3G was fairly easy to do. The trickiest part is the #3 cable that you have to push into it’s tiny slot. I also stripped one of the screws, but I figure that to be a fluke thing. I would recommend others that are comfortable opening up their electronics to make this repair.