Skip Navigation LinksHome > SSW Standards > Rules > SSW Rules to Better Source Control

I've been putting together Development Guidelines for my employer and in the process have reviewed many published standards (in the .Net arena) from around the world. In each category, the suggestions at SSW are always among the best. Leon Bambrick -
 

You should always use a source control system! SSW uses and recommends Microsoft Team Foundation Server (TFS). Source control allows the tracking of changes to code as well as a backup of your source code. This is also very useful when debugging and fixing errors as you can locate changes that have been introduced and see the lines that were updated.

Do you agree with them all? Are we missing some? Let us know what you think.

Red star Indicates important rule


  1. Do you know the benefits of using source control?

    Source control allows you to backup your code, as well as to track your changes. This is very powerful regarding debugging, fixing errors and creating release notes as you can locate previous changes and see the lines that were updated.

    With the source control (we use TFS), we can share project code and cooperate with other team members. Using it allows us to track changes, compare code and even roll-back if required. Moreover, it keeps our code safe which is the most important.

    However, the best use is the blame game. You don't just fix code, you see who broke it, fix it, and then let them know.

    Tip: It is not just about fixing problems. Always use Annotate and after fixing the problem and include a screen capture of it, letting the person who broke it know, that you just fixed their mistake.

    History
    Figure: Viewing the changes in source control on each individual file is ok
    History Compare Menu
    Figure: We can select different changesets and compare the changes
    Compare
    Figure: We can select different changesets and compare the changes. Blue = modified, Green = addition, Red = deletion
    AnnotateMenu
    Figure: Right clicking on a file and selecting Annotate to view the history on a segment basis is much better
    Annotate
    Figure: Using annotate is great. It allows us to find the coder who made the breaking changes, to understand his thoughts before deleting/changing his or her code
  2. Do you know the right source control to use? Red star

    SSW uses and recommends Microsoft Team Foundation Server (TFS) as a source code solution.

    Microsoft Visual Studio Team System
    Figure: Microsoft Visual Studio Team System

    Here are some of the reasons why:

    • Checkin policies
    • Integrated Work Items and Source control
    • Visual Studio IDE integration
    • Code Metrics
    • HTTP access via webservices
    • Integrated Build Server

    We also use Subversion (SVN) and Visual Source Safe (VSS) as needed

  3. Are you very clear your Source Control is not a backup repository?

    Only check-in code that is compiling and unit tests are working.
    Note: If you are not finished working:

    • TFS put changes into shelveset
    • SVN put changes into sandbox / branches

  4. (Before starting) Do you follow a Test Driven Process? Red star

    Never allow a situation where a developer can check out code and the code does not compile – or the unit tests are not all green. This is called “breaking the build” and the punishment in our office is 20 pushups and fixing broken links for an hour!

    Bad Process
    1. Check out
    2. Compile
    3. Develop
    4. Compile
    5. Check In
    A Bad Developer
    Good Process
    1. Get latest
    2. Compile
    3. Run Unit Tests
    4. If Tests pass then start developing
    5. Check out
    6. Develop
    7. Compile
    8. Run Unit Tests
    9. Get Latest (Always do a Get Latest before checking in as code you didn't change could break your code)
    10. Compile
    11. Run Unit Tests
    12. Check In if all tests passed
    13. Run Unit Tests to confirm everything is working
    A Good Developer
  5. (After work) Do you only check-in code when it has compiled and passed the unit tests? Red star

    Too many people treat Source Control as a networked drive. Don't just check-in when the clock ticks past 5 or 6 o'clock. If code doesn't pass its unit tests or won't even compile put your code in a shelveset

    Other recommendations have included using //TODO or commenting the code out. However we recommed avoiding this practice as it increases the risk that the code is forgotten about.

  6. (Check-in regularly) Do you keep chunks of work small, check in after completing each chunk of work (which should be before lunch and dinner)? Red star

    Frequently developers work on long or difficult features/bugs and leave code checked out for days or worse still weeks.

    1. What happens if your laptop hard drive dies?
    2. What happens if you call in sick?
    3. How can you pair program if not sharing your changesets?

    That's why source code should be checked in regularly. We recommend a check-in:

    If the changes would break the build or are in a state that cannot be put into the main trunk, then this code should be put into a shelveset (sometimes referred to as 'sandbox') in source control.

    Another good reason to check-in regularly is that it makes it easier to merge your changes with other developers. If all developers check-in lots of changes in one go, you will spend a lot of your time resolving conflicts instead of doing work.

    TIP: How can you enforce regular check-ins? Monitor them using a report to see who has not checked in.

  7. Do you enforce comments with check-ins?Red star

    Team System is great, but there are some standard features in other source control systems that aren’t available. One of the glaring omissions is enforcing comments when checking in code. Without comments, some of the other built in features like History become redundant without comments.

    Revision List
    Figure: Bad Example: No Comments against the check-ins we don’t know what changes were made in each revision
    Revision List
    Figure: Good Example: Now we can pin point which revision a particular change has been made

    To enforce this behaviour, you will need to:

    1. Install Team Foundation Server Power Tools v1.2
    2. Right click the Team Project in Team Explorer > Team Project Settings > Source Control
    3. Revision List
    4. Select the Check-in Policy tab
    5. Click Add
    6. Select the Changeset Comments Policy
    7. Revision List

    Now the next time someone checks-in some code, they are forced to enter a comment.

  8. Do you know the comment convention you should use?

    New, Bug or Refactor should be the prefix.
    Here are some examples:

    • New P112: Added a new control for DateOfBirth
    • Bug P113: Fixed validation to now allow US dates
    • Refactor: Moved the email regex from inline to a resource file

  9. Do you know the best Project/Version conventions?

    Having a good folder structure in version control allows everyone to know where everything is without even having to look.

    /northwind
    	/trunk
    	/branches (or shelvesets)
    		/experiemental-feature1
    	/releases (or tags)
    		/1.0.0.356
    
    Figure: Bad example, SVN conventions are a dated and ignore releases, hotfixes and Service Packs

    Trunk is the old way, Main is the new way as per the branching guidance, and it is the way that Microsoft does things.

    Main branch guidance
    Figure: Good example, this makes a lot more sense
    More Information:
    Good format for the information
    Figure: A good format for all your Products/Projects makes it easy to know where things are and what they are for

    Read the TFS 2010 Branching Guidance - http://tfsbranchingguideiii.codeplex.com

  10. Do you label your versions and releases in Source Control?

    TFS takes labeling to a new level unlike VSS which was a point in time label. TFS labels each file based on their changeset version. You can then get code as it was when you labeled the source.

    Labeling a release is a good way to go back to a version and generate a compiled version. If you wanted to develop an older version then you would create a branch instead (of course you can create a branch off a label)

    Figure: Get a specific version in TFS based on a label
  11. Do you know how to structure your version numbers?

    • Major - rarely change - only with major upgrades, new platform - (e.g. office 2007)
    • Minor - new features / release (customer facing) - 3 months
    • Revision - starts at 0, in ideal world, we have 0. Emergency maintenance or security patches to the customer
    • Build - internal build number for QA to differentiate (auto updating)
    See SSW Rules - Rules To Better Code

  12. Do you check-in all files? Red star

    When working on a task spanning multiple files, do not check-in only one or two of the files, this leads to the problem of partial check-ins where references to new classes or methods are unavailable because they are in the files that haven't been checked in. So either, check-in all the files you are working on or none at all if you aren't finished working on the task.

    1. Make Visual Studio remind you to check code in

      In Microsoft Visual Studio. NET sharing project code can be configured by ticking the two checkboxes on top, in Options (from the Tools menu) as shows below.

      VS.NET 2008 Source Settings
      Figure: Check-in files automatically the 2nd checkbox is very important so you get reminded to check-in your project when closing VS.NET. You know how frustrating it is when you want to fix an application and all the files are checked out by some one else!

      What about VB6 applications ?
      In Visual Basic 6 this is done by going through Tools -> Source Safe -> Options and setting it as shown in the diagram below.

      Source Safe VB6
      Figure: You can also check-in automatically in VB6

      What about Access applications ?
      We also use VSS for Access projects. Access 2000 had problems with MDBs (not ADPs) but Access 2003 works fine with both. The only thing you have to be careful of is that if a form is not checked out, it still lets you modify the form, but when you close the form, it rolls back to the VSS version and you lose all of your changes.

      Source Safe Access
      Figure: You can also check-in automatically in Access
      Source Safe Access Menu
      Figure: All the basic functions are easily accessible.

      Note: Using VSS in Microsoft Access has a few limitations, most significant of which is the inability to reattach to VSS projects.  Once you have detached from a VSS project, you will need to create a new VSS project in order to place the Access application back into VSS.

      What about SQL Server Databases?
      We save the scripts of every SQL Server schema change in Source Control.
  13. Do you use shared check-outs? Red star

    In conjunction with regular check-ins, files in source control should never be locked unless absolutely necessary. Use either 'Unchanged - Keep any existing lock' - or 'None - Allow shared checkout'.

    Only use 'Check Out - Prevent other users from checking out and checking in' when checking out binary files e.g. Word documents or third party compiled dll’s. (This will be the default this will be the selected option due to the inability for binary files to be merged on check in.)

    Check-out settings for files
    Figure: Correct checkout settings at the file level - don't lock files

    Do not enforce single check-out at the project level - make sure the 'Enable multiple check-out' option is ticked under Team Project Settings, Source Control.

    check-out settings for team project
    Figure: Correct check-out settings at the team project level - enable multiple check-out's.
  14. Do you have a report to see who has not checked in?

    Managers should regularly check to see if developers are committing their changes into source control. In TFS you can only get a status by manually looking at each project or running "tfs status" command. A great tool is Attrice Team Foundation SideKicks which can display the status of all users and projects

    Source Safe VS.NET
    Figure: Use TFS Sidekicks and search for files older than 48 hours to find the naughty boys.
    Suggestion for TFS Sidekicks: Add a button to “Email all people their shame list”…. showing their files that are still checked out (until then I do it manually)

  15. Do you only check out the files that you need?

    Checking out files that you do not plan to modify could confuse other developers on what is currently being worked on , as well as making it difficult at check-in time to see what files you actually have modified.

  16. Do you avoid limiting source control to just code?

    You can spend valuable developer time on every part of a project. The bulk of time is normally spent on coding up .cs, .vb, .resx and .aspx files. However, you could potentially have the following happen if you do not include other files in source control:

    • lose work
    • lose old versions of work
    • have work overwritten

    In particular, you should make it as easy as possible to see who changed what and who deleted what and allow a simple rollback to previous versions of non-code files. Files you should put in source control include:

    • XSL files
    • Word documents
    • Excel Spreadsheets
    • Visio Diagrams
    • HTML files
    • Image files, Flash animations and psd files  (yes this takes room in your source control database - but we still want to be able to revert to an old version easily)

    Things you don't store are:

    • Video source files (e.g. *.avi) - Store your videos on a file server instead (e.g. \\fileserver\DataNorthwind\Videos)
    • Installers (e.g. *.msi)
  17. Do you include original artworks in Source Control?

    Your original digital artworks are part of your asset and they also need to be managed accordingly. However many organizations fail to realize this and issues starts to arise when you need to roll back your images only to discover that the designer has overwritten the old images or worse, the image was designed spontaneously and the original design was exported to a .jpg or .gif without the original design being saved! Including your original artworks in SourceSafe can be handy in case of hard drive failures or accidental deletions.

    Figure: Include your original artworks in Source (eg .PSDs in Source Control)

    We chose to exempt uncompressed video files as they tend to have large footprints and potentially cause delays in productivity. It is highly recommended that you have a separate backup procedure for these files.

  18. Do you know how to rollback changes in TFS?

    Whilst working on a new feature all morning I’ve realised that this isn’t going to work out. I need to revert back to what the code was this morning before I touched it. But how?

    There are two ways to do this:

    1. If you haven’t checked in any files since you started modifying them then the process is simple:
      • Right click your solution and Undo Pending Changes
      • Undo Pending changes
    2. If you aren’t so lucky and have made some commits along the way then the only option is to use the Rollback command.
      • To use this you will need to install Team Foundation Server Power Tools v1.2
      • Find the revision before you started checking code in using the History command
      • Revision List
        Figure: The last revision before Tristan made changes was 5367
      • Open the Command Prompt in your current working directory and type “c:\Program Files\Microsoft Team Foundation Server Power Tools\tfpt.exe” rollback /changeset:5367
      • Rollback Changeset
      • Click Yes and the rollback will proceed

    It would be nice if there was a GUI for this tool so that I can just right click and select rollback. See Better Software Suggestion – TFS

  19. Do you configure your TFS to be accessible from outside the network?

    It is important to have source control available to you wherever you are, so that means than VPN access is not enough. This is because sometimes when you are working on-site, the client may have strict network policies that block VPN or even port 8080 is blocked.

    Tip: You can slove this with TFS Extranet Support:

    • TFS SP1
      This feature called "Extranet Support" was added way back in TFS 2005 SP1 as per Stuff in the pipe for Team Foundation Server
    • A domain name or IP address forwarded to TFS (eg: tfs.your-domain.com)
    • Port 8080 (this is port that TFS uses for source control)
    • Firewall/Router rule (ideally)

    Yes Port 8080 will work in most cases but not on the strictest networks, where only Port 80 is allowed.
    Then you have to use port forwarding via a firewall/router rule (recommended) to forward port 80 to the TFS port, while in this way, you would lose the TFS SharePoint Portal and Reporting Services.

    Rule to forward port 80 to the TFS port
    Figure: Rule to forward port 80 to the TFS port
  20. Do you configure your Team System Web Access to be accessible from outside the network?

    If you have Team System Web Access installed and you need to access it from wherever you are, you can configure a port to be forwarded to the server where Team System Web Access is installed, eg: tfs.your-domain.com:8090.

    Visual Studio Team System Web Access Power Tool
    Figure: Visual Studio Team System Web Access Power Tool
  21. Do you use SSW Agile Template for SSW project?

    We have developed a customized TFS team project template which includes customized reports like SSW Release Plan Report and SSW Project Progress Report. You can get SSW Agile Template from here SSW for Agile Development Template

    Follow the documents in the download package to create new team project or upgrade from existing team project in TFS.

  22. Do you use the Windows Explorer Integration

    1. Install the TFS Power Tools
    2. When you install this, make sure you do a 'Custom Install', and select the 'Shell Integration' option (this is off by default)
    Use Windows Explorer
    Figure: Using Windows Explorer for your source control is a dream (great for designers too - who don't want to use VS.NET)

    Suggestion to the TFS Team: I didn't see blame annotate in the drop down - which is a bit odd.

    More reading from the prolific Brian Harry:
    http://blogs.msdn.com/bharry/archive/2008/11/08/oct-08-tfs-power-tools-are-available.aspx
    http://blogs.msdn.com/bharry/archive/2008/10/01/preview-of-the-next-tfs-power-tools-release.aspx

  23. Why are we still keeping VSS?

    Because we still have some projects left over in VSS, they cannot be upgraded to .NET 2.0 and checked in to TFS.

    Project Note
    SSWFramework For 1.1 apps and fix criticle bugs(if needed)
    SSWFrameworkSamples Framework samples
    SSWRegistration For 1.1 apps and fix criticle bugs(if needed)
    SSWSQLTotalCompare VB6
    SSWTeamCalendar Asp (will be upgraded to asp.net soon)
    So, when you are working on SSWSQLTotalCompare and SSWTeamCalendar, you should still use old VSS database. These two projects are referencing SSWFramework and SSWRegistration, so they are kept as well; but only for critical bug fixing.
    Also, if there is any client work (1.1 version) referencing these projects, you should still use these VSS versions. At the same time, keep in mind that we have already upgraded to TFS and you should try your best to convince the client to upgrade.

  24. Do you need to migrate the history from VSS to TFS?

    Suppose you are migrating from VSS to TFS, you need to consider if it's necessary to also migrate the history.

    We suggest that you don't migrate the history, because:

    • Normally, you don't need to check the history very often. If you do need sometimes, then get it from VSS.
    • Save much space for TFS. For example, we have a about 7G VSS history database, and we may only need a small bit of them every 3 months, so what's the point of coping about 7G file when we only need one line of code?

    But there are also some considerations that you may want to migrate the history:

    • If the history of source changes will be checked very often, so you can check the old history with the recent together via TFS.
    • You are going to decommission the old VSS completely. Say you don't want to keep the old VSS database, and then it will be necessary to keep the information somewhere.
    • If the project is very active, then it will be worthy to migrate the history because your developers may need them every day.

    If you are going to move the history, the links may help:

  25. Do you know which check-in policies to enable?

    Check-in policies are a great tool to enforce quality code before it hits your source control repository. SSW recommends that the following check-in policies be enabled by default on your project:

    1. Changeset Comments Policy - To enforce that all check-in contain comments
    2. SSW Code Auditor - To enforce coding standards and best practices before check-in
    3. Testing Policy - To enforce that unit tests should all pass before code can be checked-in

    To enable these policies:

    1. Right click the Team Project in Team Explorer > Team Project Settings > Source Control
    2. Select the check-in policies above
    3. Click OK
    Chose check in policy
    Figure: Chose check-in policies in TFS

Acknowledgments

David Klein
Tristan Kurniawan
Ryan Tee
Justin King


Benefit from our knowledge and experience!

SSW is the industry leader in Custom Software Development, Software Auditing & Developer Training.

Call us on +61 2 9953 3000 or email us for a free consultation

What does it cost? I’m not in Australia. Can you still help?