Thursday, May 24, 2007

On the virtues of crap code

Sometimes you just have to wonder what people are thinking. What level of software engineering degree does it take to completely misunderstand a concept and write this very special code?

SqlConnection conn = _db.GetConnection();
SqlTransaction tx = conn.BeginTransaction();
SqlCommand cmd = this.GetCmdRemoveField(conn);
cmd.Transaction = tx;
cmd.Parameters.Add("@ID", id);
cmd.Parameters.Add("@FieldName", field);
try { tx.Rollback(); }
catch { }

My eyes bleed and my heart sunk as I found this code from an external development group that was developing part of the previous application I worked on.

kick it on Shout it

SQL Deadlock Troubleshooting

SQL deadlocks can happen in the funniest places and when you least expect them. Take for example one website that had no problems with 1-2 users, but when 'scaling' to even 4 users SQL deadlocks would start. The blog entry below is well worth the read to help debug those pesky deadlocks.

Bart Duncan's SQL Weblog : Deadlock Troubleshooting, Part 1

kick it on Shout it

Thursday, May 17, 2007

Can Agile Methodology be adapted for stand-up comedy?

The age old question. Once you feel the power of the Agile methodology you may too find yourself looking for other parts of your life to apply it.

kick it on Shout it

Continuous Integration with Subversion and AssemblyInfo

Building a continuous integration environment is becoming easier every day. How nice is it to have all of your source code automatically versioned with each build from continuous integration?
Here are some steps that might help when using Subversion:

A task to retrieve the latest subversion change number from the repository

<echo message="Retrieving Subversion revision number"/>
<property name="svn.revision" value="not_available"/>
program="c:\program files\subversion\bin\svn.exe"
commandline="log ${code.trunk} -r HEAD --xml"
<echo message="Using Subversion revision number: ${svn.revision}"/>

Now add a task that will update all of the CommonAssemblyInfo.cs and AssemblyInfo.cs files that have the AssemblyVersion attribute defined.

<target name="SetVersions" description="Stamp the version info onto assemblyinfo.cs files">
<foreach item="File" property="filename">
<items basedir=".">
<include name="**\AssemblyInfo.cs"></include>
<include name="**\CommonAssemblyInfo.cs"></include>
<script language="C#">
public static void ScriptMain(Project project)
StreamReader reader = new StreamReader(project.Properties["filename"]);
string contents = reader.ReadToEnd();
string pattern = @"\[assembly: AssemblyVersion\("".*""\)\]";
if (Regex.IsMatch(contents, pattern))
string replacement = string.Format(
"[assembly: AssemblyVersion(\"{0}.{1}.{2}.{3}\")]",
string newText = Regex.Replace(contents, pattern, replacement);
StreamWriter writer = new StreamWriter(project.Properties["filename"], false);

And now tie it all together with this little task before executing your build, and you should have an accurately versioned build every time!

<property name="build.version.major" value="1" />
<property name="build.version.minor" value="0" />
<property name="" value="0" />
<property name="build.version.revision" value="*" />

<target name="UpdateVersions">
<call target="RetrieveSVNChangeNumber" />
<property name="" value="${svn.revision}" />

<call target="SetVersions" />

Of course the next step could be to check in all of those updated assembly info files...

kick it on Shout it