I have assembled the Triforce

Recently I put in the final piece of a mini project I’d been thinking about for a while.  I made a change to an Agent Ralph source file and committed it to my Mercurial repo.  Within about a minute I was browsing the MbUnit test results.  Now that may not sound very exciting, but it is.  It is because all of this was conducted online, through my browser, on a pc that didn’t have Mercurial, Visual Studio, or any development tools whatsoever.  I was coding in the cloud, baby.

Now with Agent Ralph I have boiled my unit tests down to the point where they are just code snippets.  Adding a new test case is as simple as dropping a csharp file into a directory.  It is automatically picked up and fed into a test harness, which parses the code and gets all Ralphy on it.  Here’s a sample, right out of the repo:

using System;
namespace AgentRalph.CloneCandidateDetectionTestData
{
    public class CloneInForeachBlock
    {
        void Target()
        {
            foreach (int i in new int[] { })
            {
                /* BEGIN */
                Console.WriteLine(7);
                /* END */
            }
        }

        private void Expected()
        {
            Console.WriteLine(7);
        }
    }
}

This sample comes from the CloneCandidateDetectionTestData folder.  Any file in that folder is assumed to hold a class containing at least two methods, Target and Expected.  Target is scanned for clones, and the test passes if a clone is found that matches Expected AND consists of all the code between the START and END ‘markup’ embedded in the comments.   Thanks to the magic of MbUnit’s generative tests each code file appears as it’s own test, as if each were a method with it’s own [Test] attribute.  So you see, whipping up new tests is crazy easy.

Occasionally an idea for a test case will come to me, and it’s usually when I’m at a place where I have no access to Agent Ralph code.  Like work.  Typically I’d make some notes in an email and code it up when I got home.  It got me thinking, I don’t really need Visual Studio and the whole dev setup to create these test cases.  They’re just simple code snippets, scraped out of a directory.  I could be scraping them from anywhere, like off a wiki even.  The next thought of course was to run that test automatically.  How could I put this all together?

Building and running tests is easy, any continuous integration server would do.  I chose TeamCity, which we’ve been using at work and is just great.  I can’t say enough nice things about it.  For this mini-project, it’s easy third party report integration and build artifact downloading features were exactly what I wanted.  A little dyndns magic and I had it online.  My MbUnit tests look pretty nice I think.

At some point I stumbled across Bespin.  Bespin is a Mozilla project that “proposes an open extensible web-based framework for code editing”.  It’s a web based, code centric text editor, and more.  One part of the more is version control integration.  Mercurial is supported, which is what I use for Agent Ralph.  I can pull down the code, hack on it, and push changes back out to the Google code hosted repository, all right in the browser.  There’s the missing piece, my editor.

And of course, Google Code is the glue that brings them together.

And there you have it, coding in the cloud!  This graphic ought to help you fully grasp the awesomeness.

MyForce

The Oscillating Shrinking Window

I talked previously about how Agent Ralph identifies functionally equivalent methods.  It also can find clones embedded within a method, as shown at the end of my last post.  This time I’ll talk a bit about how that works.
Agent Ralph’s preferred unit of comparison is the method.  The comparison implementation accepts two methods and walks their ASTs, [...]

Agent Ralph In Action

I’ve been yack yack yacking about clone detection and Agent Ralph.  It’s time to put up or shut up.  This post is some screen shots of Agent Ralph in action.
Agent Ralph’s front end is a Resharper plug-in.  Any clones detected are passed up to the plug-in which presents them to the user as highlights and quick [...]

An Idea For Robust Clone Detection Using Abstract Syntax Trees

My last post concluded with the promise to go into detail on some implementation ideas of my clone analyzer.
As I argued previously, a text based matching tool is not good enough, it’s simply too easy to fool. What we want is a matching tool that considers the full syntax of the language being analyzed. [...]

Code Clones

Code clones are code constructs or functionality that is repeated throughout a system.  It’s a well documented problem.  In short, the issue is duplication of logic.  Take this example:
double Area(double radius)
{
return 3.14*Math.Pow(radius, 2);
}

double ComputeArea(double radius)
{
return 3.14*Math.Pow(radius, 2);
}
Two functions identical in every way except name.  The cost of future [...]

Unnecessary Complexity Case Study #1: Untyped Enum Comparisons

This post is the first in a series of posts on specific examples of unnecessary complexity.  
Consider this code:
enum MyEnum  { First, Second }
public void Match1(MyEnum e)
{
    if (e.ToString() == “First”) { }
}
The problem lies in the condition of the if.  The developer is converting an enum instance to a string for the purposes of [...]

Unnecessary Complexity

A lot of the work I’ve done recently has involved substantial improvements to largish production code bases.  Currently I’m working on a system of .Net apps that seems to have experienced exponential LOC growth in the few years of it’s development.  Before that I was doing maintenance and upgrade work on an app that started [...]