Is Your Source Code Protected?

Matthew Campbell, July 6th

When I say “is your source code protected”, I really mean from YOU!

Sometimes when you are working on your code you have a great idea and to implement it you have to change a ton of files. If you are working with others they may decide to do the same thing. This is all fine and dandy until it ISN’T and your app will not run anymore!

OH NOES!

How do you fix it? Will I be up all night tracing a trail of bread crumbs back to the previous state to get the thing working again. *Uggg* My changes are spread across tens (hundreds, thousands) of files!

If you ever wished that you could “just go back” to the point right before you made your changes then you could use want is called a “version control system”.

Version Control System

If you never really worked in programming professionally on a team you may not even be aware of the idea of a VCS. Think of a VCS as a more sophisticated version of the filesystem you are used to working with.

Check-in, Check- out and Branching

Instead of simply opening files up you need to perform some action to either give yourself exclusive permission to edit the file or to create a “branch” that only you can work until you decide to make the changes “official”.

Essentially you are telling the VCS that you are going to work on files, but the main project will not be affected. If you make a mistake you can simply disregard the changes and the project will not be affected.

The Nice Thing About This

The nice thing about this is that you can try a bunch of different things and if something goes wrong it is easy to go right back to where you started. If you are working with others, then a VCS is essential because it will stop you from working on the same file at the same time or it will provide a mechanism for merging the changes that you and your teammates made.

3 VCS on the Mac

I’ve been programming on the Mac for a year now, but I have to admit that I have not yet set up a VCS. When I worked on Windows we used something called Source Safe which followed a check-out/check-in model. Last week, I investigated a system called Git that uses the branching model.

There are a few choices and this is something you may want to have in place before you start working with others. Here are three VCS you can use with XCode:

XCode Snapshot

XCode comes with a built in VCS. Open XCode and look under File and you will see an item called “Make Snapshot”. This is meant to be like taking a picture of your code that you can go back to later if you need to. If you use this to take a picture of your code then later you can use the “Snapshots” menu item to go back to the state your code was in when you took the picture.

Subversion

I have not yet investigated this system yet, but I do know that Subversion is a VCS that offers more than the built XCode functionality. It will help you with collaboration and so on. Subversion is nice because it can easily be integrated into XCode and it is commonly used on the platform.

Git

Git is another VCS you may encounter – many developers make their code available with Git that you can use freely. Git uses a branching model – essentially, you create a branch for your project, work on the branch and then merge it back into the main project if it works. The biggest distinction with Git is that developers can use shared resources even when they are offline (good for when you want to work on a plane).

One thing about Git – there does not seem to be a way to really integrated it with XCode. So, you may find yourself using some third party tools and the command line to use this VCS.

Last Words

Clearly this is a “do as I say, not as I do” category of post. But, I can tell you that it is nice to have your code protected with a VCS. It is even better if you move your code to a remote host. Privately hosting your source code on a server will cost you a nominal fee, but if you collaborate you will want to do that. As I investigate more VCS I will post the details here – Stay Tuned!

here is a nice article on implementing subversion from Jeff Lamarche’s blog:

http://iphonedevelopment.blogspot.com/2009/03/version-control-is-your-friend.html

Awesome thanks! I will read that over tomorrow – last week I tried Git, now onto Subversion. If it integrates I may just go with that.

[...] are some other pages (1, 2) that reference subversion and source control [...]

I have started using an online svn site called codespaces.com. It’s a great idea.

Is Your Source Code Protected?…

You’ve been kicked (a good thing) – Trackback from iPhoneKicks.com – iPhone SDK links, community driven…

  • Hours of videos, demos & screen casts
  • SOURCE CODE
  • Detailed HANDS-ON Exercises
  • Much Much Much More
  • UIKit
  • Objective-C
  • Core Data
  • More!
  • Learn How To Make An iPhone App right now using my proven system.

    PS: Tons of us are having a blast living off our own code, join us now. Click here to get all the details.