When To Branch in Version Control

When you are developing a product that has a live version, yet you wish to perform enhancements to the application.  How do you cope with the version control (you do use version control…) of fixes or enhancement to the live version.

The solution here is to use a branch.  The branch must be from the labelled point (you do label/checkpoint builds) used for the live build.  The trick is to keep the branches as small as possible and keeping as few maintained. It adds complexity to the development task but allows development to continue. Only create the branch at the point that you need to make changes.

Possible work-around for DatagridView bug

This is a link to a work around to the reentrant issue on a win forms DataGridView.

The reentrant issue raises it’s head when changing data in a DataGridView. InvalidOperation exceptions get raised a random time after the grid is changed. This implies that the DataGridView uses threads in the background yet it’s public methods are not thread-safe.

In order to solve this you should use the best practice of subclassing the UI controls and put the fix there.

Theoretically you should subclass all controls (see here) – but if pushed for time just do the complex ones (how many times will you bugfix a label?) or the subset that you use frequently – any app will mostly use 10 or so basic controls.

MSDN Magazine Lag Time

I have been reading MSDN Magazine (and it’s predecessors MSJ and Visual Developer) for a number of years now.

Until recently there has been upto a 5 year lag between an article being written and being able to use it in anger.

Today I finally found a use for an article written in June last year (only 8 months behind)!

A really useful feature  especially when combined with  Code Generation:

(I have given up on adding tags around XML) 

ItemGroup
    Compile Include="*.cs"
/ItemGroup

This allows code to be added to the project without having to explicitly edit the project file.  

Simple DataGridView Sample

This is almost all you need: 

            string connStr = “Data Source=(local);Initial Catalog=Northwind; Integrated Security=SSPI;”);
            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = “SELECT * FROM Products”;
            DataSet dataset = new DataSet();
            SqlDataAdapter dataadapter = new SqlDataAdapter(cmd);
            dataadapter.Fill(dataset,”FOO”);
            dataGridView.DataSource = dataset.Tables[“FOO”];
            dataGridView.Columns[0].Visible = false;

Rules for Object Composition

I have found the following rules make reuse easier:

  1. Contained objects should not be aware of the container.
  2. Containers should be aware of the contents.
  3. Event handlers should be used for communication from the contained to the container.
  4. Inter object event handlers should be established by the Container and should be explicitly set up in code.

These simple rules permit reuse of the contained control.  Objects developed along these lines are much easier to extend and reuse.  It also makes it very quick to rearrange the top level container. 

These rules also apply recursively so that a container may be contained in an outer container. 

Boo and MSBuild

Msbuild is microsofts answer to Ant. This is a build tool for the .Net Platform.

It has the minor benfit of being the native file format of the Visual Studio 2005 project files.

You need the .Net Framework 2 installed and to add the Microsoft Framework to your path statement

Boo is a lightweight .Net language.

Here is a sample that gets a task written in Boo for msbuild:

=== MyTask.boo ===

import Microsoft.Build.Framework
import Microsoft.Build.Utilities
import Boo.Lang

class MyTask(Task):
public override def Execute():
Log.LogMessage(MyProperty)
return true

private _MyProperty as string

MyProperty as string:
get:
return _MyProperty
set:
_MyProperty = value

=== Test.proj ===

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
DefaultTargets="MyTarget"
InitialTargets="BuildMyTask"
>

<Target Name="BuildMyTask">
<Exec command="booc MyTask.boo -t:library"/>
</Target>

<UsingTask TaskName="MyTask" AssemblyFile="MyTask.dll"/>

<Target Name="MyTarget">
<MyTask MyProperty="Hello!"/>
</Target>
</Project>

===

You also need Boo installed (and on your path).
Copy Boo.Lang into the directory that you created these scripts in.

At the command line type: msbuild
This will build and run the minimal boo task.
I am planning to add a real msbuild task for boo.