Resharper

I’ve been using Jetbrains Resharper for seven months now, and continue to find fantastic shortcuts. I can’t imagine going back to programming without it. It doesn’t just make things easier, it dramatically increases the likelihood that you’ll tackle important changes to your code base. Press ALT-INSERT and a window pops up that let’s you add constructors, properties, or overrides, each of which gets inserted with the proper signature and access level. That saves a lot of time. Better yet, you can write code that calls methods that don’t exist and Resharper will put an icon next to the call. Click in it and it offers to implement the method for you — in the right class, in the right module, and (to the best of it’s abilities) with the right arguments.

It also lets you jump through the code intuitively. If you’re looking at a function call, and you wonder, what does that function look like? Press CTRL-B and up comes that function. If you then wonder which other functions, if any, call the function you’re looking at, press ALT-F7 and a window pops up with every usage in the project.

There’s a complete list of Resharper shortcuts here.

The virus

I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We’ve created life in our own image.
  - Stephen Hawking

Just for fun, some Javascript

I’ve learned a lot about web programming since taking this job. I knew C# already, but ASP.NET, XML, AJAX, and all that was new. I didn’t know any Javascript either, nor did I understand what an important role it plays on the web. But that changed this week, when I was given the assignment to use Javascript to make the header cells in a column change color in order to improve the user interface of a large table.

Once I got that working, I threw this sample together.

The most important thing I learned is that ASP.NET often auto-generates element IDs, which means that refering to elements by the ID used in the code will fail. The solution is to use the ClientID property of the element to obtain the “real” ID that will be produced in the HTML.

Attaching the script is a two-part process. First, the script to be associated with each table cell is attached using the Attributes property.

for (int r = 1; r < table.Rows.Count; r++)
{
    string rowID = table.Rows[r].Cells[0].ClientID;
    for (int c = 1; c < table.Rows[r].Cells.Count; c++)
    {
        string colID = table.Rows[0].Cells[c].ClientID;
        TableCell cell = table.Rows[r].Cells[c];
        string colScript = string.Format(”handleOver(this,’{0}’,'{1}’);return true;”, colID, rowID);
        string rowScript = string.Format(”handleOut(this,’{0}’,'{1}’);return true;”, colID, rowID);
        cell.Attributes.Add(”onmouseover”, colScript);
        cell.Attributes.Add(”onmouseout”, rowScript);
    }
}

The onmouseover and onmouseout Javascript events are mapped to script that calls Javascript functions called handleOver and handleOut. These functions both take a reference to the cell itself (this), and the client ID of both the column and row header cells.

The handleOver and handOut functions are pretty simple. They just use the IDs to change the header cell background color, and then change the cell background. 

var origColor;

function handleOver(elem, col, row)
{
    var c = document.getElementById(col);
    origColor = c.bgColor;
    c.bgColor = “#aaaaaa”;
    var r = document.getElementById(row);
    r.bgColor = “#aaaaaa”;
    elem.bgColor = “#aaaaaa”;
}
function handleOut(elem, col, row)
{
    var c = document.getElementById(col);
    c.bgColor = origColor;
    var r = document.getElementById(row);
    r.bgColor = origColor;
    elem.bgColor = origColor;
}