Social Icons

Pages

Tuesday, October 20, 2015

Use a Time Machine

Above Average Programmers can travel back in time.  At least, that is, they can travel back through their project’s history.  This is because all Above Average Programmers use “Version Control” when they work.  Version Control Systems (or VCS’s) give developers the ability to pull up any previously recorded version of their source code, right back to the beginning of the project.  What’s more, it lets them keep track of their current work more accurately, and makes it easier to work with others.  It’s even useful for stuff other than code.

VCS comes under a variety of names:  Source Control, Revision Control, Software Configuration Management (a larger topic).  Sometimes, teams just refer to it by the specific implementation they use:  CVS, Subversion, Git, Github, SourceSafe, TFS, etc.  No matter what it’s called or what the implementation is, you’ll find that you’re almost always better off with it than without it -- yes even the crappy ones.

Consider the scenario in which you are working on the next release of your code and suddenly a bug report comes in about a problem with the last release.  While you might fire up your IDE and start bug-squashing on the current, unreleased build, how can you be sure you haven’t already fixed the bug in question?  If you’ve touched the suspect section of the code since the last release, how can you even be sure that you are inspecting the right lines of code?

If you’re not using VCS, perhaps you were smart enough to create a working copy of the release version of the code for just this occasion, which is great.  Now you can confidently view the source that you know is running in release and fix the bug.  Good.  Now what?  How do you carry that fix forward to the new work you’re doing.  If the code has been modified heavily since the last release, that’s going to be one heck of a job to merge the bugfix in (although there are merge tools out there which could help).

Having a VCS makes maintaining multiple working versions of your code much easier than managing it yourself with copies.  For example, you can have a “release branch” of your code for bugfixes and a “main branch” for the upcoming release, both with their own tracked, inspectable set of changes.  It will also facilitate the merging of changes, not only from “main” to “release,” but also in the other direction for those times when you make a quick bug fix on the release branch and want to backfit it into the “main” branch where you are doing your major development.

Here’s another situation to think about:  What if your co-worker wants to help out with the code?  Sure, you could throw the code up on a fileshare and both hack on it simultaneously, or you could send zip files to your colleague every day which contain the latest version of the code, and then manually merge his or her changes back into your “master” version every day.  Both of these are fraught with trouble such as accidental overwrites, locked files, and time-consuming drudgery.

With VCS, you can both simply hook into the “repository” of source code, get your own copy of the code, and begin “checking in” your changes.  The VCS will automatically merge what it can figure out on its own and alert you to any “conflicts” resulting from complex changes you both make to the same code.

Any good introduction to VCS will also show you how to branch off from your main version and work on specific things in your code with the intention of merging those changes back in later.  This allows you to work on complex features without disrupting the main codebase for other team members.

VCS is so powerful for supporting collaboration that I believe it deserves a lot of the credit for the open source revolution in software.  If it weren’t for the easy source code management that VCS provides to distributed teams of programmers, open source would probably never have gotten to where it is now.

Here’s an extra thing to consider:  VCS can also version control things besides source code.  In fact, it works just fine with binary files like images and office application documents.  If you find yourself wishing you had previous version of files in your home directory, it is perfectly feasible to set up a VCS repository for it.  I’m not the first person to think of this:


Convinced?  There are many introductions to Source Control on the web and they will get you there faster and with more flair than I ever could.  Some of my favorites are:

Check these articles out and see what you’ve been missing.  Maybe it’s time to tap into the power of VCS as part of your journey toward becoming an Above Average Programmer.

No comments:

Post a Comment