Rewriting code without fear

Over the last few days, I’ve been rewriting some major pieces of ICanHasCheezburger.app to simplify and clean up the way I handle movies. Currently I use a single image view, which is set to a ‘play’ image for movies, which then open in the browser when clicked. I’m changing it to swap between the image view for displaying images and a web view in which I open movies.

In addition, I’ve cleaned up and simplified the way I deal with the RSS feeds I obtain the images from. Previously, I had a single FeedController class, which stored the entries obtained from a CXMLDocument as an array of CXMLNodes. To display an image, open the web page, or play a movie, I had to query the FeedController for an element of the current item.

To clean it up, my FeedController now uses an array of FeedItem objects, with properties such as permalink, image URL, movie URL, and title. I now pass a FeedItem to my root view, which uses it to decide whether to display an image or movie without having to go back and query the FeedController.

I found it to be a lot easier & cleaner to use NSXMLParser, so I can create a FeedItem for each RSS item directly rather than have to manipulate the CXMLDocument, extract each CXMLNode, and create a FeedItem for it.

Until now I’ve never used XCode’s Snapshot feature. Since I use Subversion, I figured I could simply check out an earlier revision. Before I started rewriting all of that code, I saved a snapshot. It shows exactly what has changed since the snapshot and makes it very easy to revert if something goes wrong. It’s very similar to checking in to Subversion or reverting to an earlier revision, but it’s a lot faster and more convenient. I find it very liberating to be able to make a major change like this and not have to worry about messing up, since I can easily go back to the way it was.

Snapshots

Leave a Reply