Software Development

All things programming.

Changing the AnkhSVN Merge and Compare Tools

When my team reverted back to Subversion the first thing I missed was the Visual Studio integration from TFS.  CollabNet provides AnkhSVN to fill that gap by exposing most common source control operations directly through the IDE.  I’ve been using AnkhSVN successfully for a few months but one thing that always bugged me was the default compare tool.  I love WinMerge and the default merge and compare tool just didn’t, well, compare.  Thankfully the merge and compare tools thank AnkhSVN uses are configurable.

AnkhSVN adds a Subversion User Tools page to the Source Control folder in the Visual Studio options dialog.  From here we can select the tools to use for:

  • External Diff
  • External Merge
  • External Patch

Not only does AnkhSVN provide a list of popular tools including WinMerge and KDiff, it also attempts to determine if any of them are installed and marks any it can’t find with “(Not Found)”.  To change the tool just select it from the list or enter the path to your favorite utility.

Each of the tools are preconfigured to run with a fairly thorough set of arguments but if we want to customize them we can click the corresponding ellipsis button to open the Command Editor.  AnkhSVN uses the macro paradigm to inject a variety of variables into the argument list for the selected editor.  Its macros follow the traditional $(name) format so it should look familiar to anyone familiar with configuring external tools from Visual Studio’s Tools menu.

Ever since I found these settings and replaced the default tool with WinMerge I’ve been much happier.  AnkhSVN is a much more natural extension of my workflow than TortoiseSVN so being able to use WinMerge simplifies the process immensely.

Speaking in Fort Wayne

If you missed my Parallel Programming in .NET 4 talk at IndyNDA on June 9th you now have another chance!  I’ll be giving the same presentation to the .NET Users of Fort Wayne (NUFW) on August 9, 2011 at 6:00 PM. Be sure to check the NUFW site for registration and logistics.

I hope to see you there!

NUFW Logo

VS2010: Find in Files

I really debated with myself about writing this post but after an exchange with a friend I decided to go ahead with it.  My team recently upgraded to new laptops with a fresh new image.  When one of my friends remarked that he was glad that the new image contained wingrep I asked why he didn’t just use Visual Studio’s Find in Files feature.  His reason?  He didn’t know about some of its features.  After talking about it a bit he said he’d give it another shot.  Now, several days later he’s using it almost exclusively.

(more…)

June Speaking Engagement – IndyNDA

I’ll be speaking at the 126th meeting of IndyNDA. In this session I’ll cover Parallel Programming in .NET 4 and as a bonus show some of the features included in the Visual Studio Async CTP.  I hope to see you there!

Date/Time:
6/9/2011 6:00 PM
(5:30 registration)

Location:
Management Information Disciplines, LLC
9800 Association Court
Indianapolis, IN 46280
[Map]

Be sure the check the IndyNDA site for full logistics and other information.

JustDecompile – First Impressions

I have posted a new review of JustDecompile that looks at a later beta release.

With Red Gate now charging for .NET Reflector and updating the free version to expire at the end of May I’ve been starting to think about alternate decompilation tools.  A few days ago I saw an article on InfoQ about Telerik’s JustDecompile tool and thought I’d take a look.  So how does JustDecompile fare?
(more…)

VSTS 2010 Load Test Browser Definitions

The list of browsers included in the VSTS 2010 browser list has a decent selection but with the release of IE9 and other browsers it’s already getting out of date. Luckily we can add additional browsers by creating new .browser files in Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Templates\LoadTest\Browsers (Program Files (x86) on 64-bit systems).  The files are simple XML documents that include a name and a few header items such as user agent so there isn’t really anything scary in there.  For example, the definition for IE8 is as follows:

<Browser Name="Internet Explorer 8.0" MaxConnections="6">
  <Headers>
    <Header Name="User-Agent" Value="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)" />
    <Header Name="Accept" Value="*/*" />
    <Header Name="Accept-Language" Value="{{$IEAcceptLanguage}}" />
    <Header Name="Accept-Encoding" Value="GZIP" />
  </Headers>
</Browser>

(more…)

Not Another Regular Expression

I haven’t done anything with the System.Drawing namespace directly in a long time.  So long in fact that before today I honestly can’t remember the last time I needed anything in there.  When I needed to update the border color on an old ASP.NET DataGrid and the compiler informed me that I couldn’t use a hex string I was a bit surprised.  I needed a way to convert that string to a System.Drawing.Color.

In my haste the first thing I did was start writing a method to parse out the string and get the integer values to pass in to Color.FromArgb.  Because I needed to account for both the 3-digit and 6-digit formats in both uppercase and lowercase characters with or without the leading hash I started hacking out a regular expression.

I haven’t had much reason to use regular expressions for a long time either but apparently (and amazingly) I can apparently remember their syntax better than I can remember what’s in System.Drawing because with minimal documentation referencing this is what I came up with:

var re = new Regex(
	@"^#?(?([\dA-F]{3}$)(?<r>[\dA-F])(?<g>[\dA-F])(?<b>[\dA-F])|(?<r>[\dA-F]{2})(?<g>[\dA-F]{2})(?<b>[\dA-F]{2}))$",
 RegexOptions.IgnoreCase
);

As irritating and confusing as the syntax is I’m always amazed at how powerful regular expressions are.  There’s really quite a bit going on in this example so let’s take a look at what it’s matching.  I won’t talk about the RegexOptions piece because that should be pretty self-explanatory but otherwise we can break this one down into a few pieces starting with the most basic.

We start and end with the ^ and $ characters.  These ensure that the string we’re checking is respectively the first and last thing on the line.  Immediately following the opening ^ we see the #? pattern that says a valid match will start with no more than one instance of the # character.

Throughout the expression we repeatedly see the [\dA-F] pattern.  On its own this pattern matches a single hexadecimal digit (0-9, A-F).  When we need to match multiple consecutive hexadecimal digits we follow the pattern with a quantifier like {2} or {3}.

The remaining constructs in the expression deal with groups and conditional matching (formally called alternation).  These constructs look similar and are closely related.  In this example we’re using two types grouping patterns and an alternation pattern.  It’s probably best to start with the outermost construct and work our way in.

In this example alternation construct follows the (?(expression)yes-part|no-part) syntax.  I like to think of this conditional matching construct as the regular expression version of the ternary operator.  The expression is a zero-width assertion construct (non-advancing) that is used to determine whether the yes-part or no-part pattern should be matched.  Most of the time the construct for a zero-width assertion begins with (?= but in this case the assertion is is implied and the .NET regular expression parser allows us to omit the ?=.  In this example our zero-width assertion is ([\dA-F]{3}$).  That is, we’re evaluating whether the string matches exactly 3 hexadecimal digits followed by the end of the line.  In short, if the string is a 6-digit format the parser will match the “yes” part otherwise it will match the “no” part.  The reason we’re asserting the end of line here too is that we want to ensure that a 6-digit color doesn’t fall in to the “yes” part.

Note: Alternatively we could assert [\dA-F]{6} and swap the yes/no parts.

The “yes” and “no” parts are very similar in that they both consist of three named capturing groups: “r”, “g”, and “b”.  The named capturing groups are identified by the (?<name>pattern) syntax and instruct the parser to remember the values for use later in the pattern through backreferences or returning to C# via the Groups collection on the Match object.  Since we’ve really covered what the pattern does we won’t go into detail here.  We just need to recognize that when we’re matching a 3-digit color we capture the individual digits whereas when we have a 6-digit color we capture pairs of digits.  By using the same names in both parts our C# code can be completely ignorant of how the expression captured them.

Note: Regular expressions also allow for unnamed capturing groups that can be referred to by their ordinal index.  Even though they add clutter to an already potentially confusing string I usually stick to the named capturing groups because they make it easier to remember which group I’m working with.

This regular expression did the trick nicely.  I was able to extract the individual color components from both 3-digit and 6-digit color codes and fail out of anything that didn’t match by checking the match’s Success property.  Unfortunately this was only part of the conversion process.  I still needed to convert the values from the 3-digit pattern over to their 6-digit equivalent and pass the integer values to Color.FromArgb.  At this point I got to thinking “there has to be an easier way” as though the regular expression wasn’t enough.

No matter how far you have gone on a wrong road, turn back.
– Turkish Proverb

Remember that I said that I haven’t done anything with the System.Drawing namespace directly in a long time…  It turns out that there’s a ColorTranslator class in System.Drawing that provides a nice FromHtml method.  FromHtml takes a hex string and returns the equivalent System.Drawing.Color.  Problem solved.

KalamazooX 2011 Recap

I attended the 2011 Kalamazoo X conference in Kalamazoo, MI on April 30, 2011.  There were no family emergencies this year which was great because this year’s event was even better than last year’s!  I’d like to extend another huge “THANK YOU” to the organizers and speakers for making it happen again.

For those unfamiliar with the Kalamazoo X conference it’s not your typical software development conference.  While most software development conferences focus on technical skills, Kalamazoo X focuses on the often forgotten soft skills.  Also unlike other software development conferences Kalamazoo X only has one track of consisting of highly focused 30 minute sessions.  This format is perfect for my limited attention span.  I feel less tired after this conference than I typically do with others of similar length despite being bombed with a steady flow of information.

(more…)

My Day of Agile

On March 26th I attended the Cincinnati Day of Agile conference.  It was nine hours and three tracks of talks and discussions about using Agile practices to build software.  The first track focused on introducing Agile concepts and techniques while track two was more about “soft” skills and getting the most out of Agile.  Track three was mostly an open space type track.  Despite still being a relative n00b to Agile I spent my day bouncing between tracks two and three.  What follows are my notes and thoughts from the sessions I attended.

(more…)

Parallel Programming in .NET 4

Over the years software development has relied on increasing processor clock speeds to achieve better performance.  For better or worse though the trend has changed to adding more processing cores.  Generally speaking, software development hasn’t adjusted to account for this transition.  As a result many applications aren’t taking full advantage of the underlying platform and therefore they’re not performing as well as they could.  In order to take advantage of multi-core and multi-processor systems though we need to change the way we write code to include parallelization.

Historically, parallel programming has been viewed as the realm of highly specialized software where only experts dared to tread.  Parallel programming aims to improve performance by executing multiple operations simultaneously.  The .NET framework has always supported some level of parallel programming.  It has included threads and locks all the way back to the early days of the framework.  The problem with threads and locks though is that using them correctly is difficult and error prone.  Where do I need locks?  Can I lock on this?  Should I use lock, ReaderWriterLock, or ReaderWriterLockSlim?  How do I return a result from another thread?  What’s the signature for the ThreadStart delegate passed to the Thread constructor?  These questions haven’t even started to touch on pooling, deadlocks, exception handling, cancellations, or a multitude of other considerations.  .NET 4 doesn’t eliminate these classes but builds upon them.
(more…)