I've probably said it before, but it's amazing how much a change of scenery can help you grow. I've been pretty busy coding a prototype web service with heavy test coverage and extensive business logic - all backed up by NHibernate. Here are a couple things that I've either re-learnt or learnt in just a couple days.
Twitter
First, I'm trying to twitter. Hopefully twittering is something you can get better at, 'cuz the whole thing feels awkward. You can check me out at http://twitter.com/karlseguin/. And if you do twitter, a colleague and I built a simple site that lets you create messages more than 140 characters: http://tweeeet.com/
Add As Link
I'm embarrassed to say that I had no idea you could Add as Link in Visual Studio. When you do so, it's like adding a shortcut to a file to your project. Just "Add an Existing Item", pick the item you want to add, but instead of clicking the "Add" button, click the arrow next to the "Add" button and pick the "Add as Link" option - I'm not a fan of the button/dropdown hybrid. I've been using this with my StructureMap.config file - which I tend to copy around for unit tests, or test console applications. Also, and more importantly, it's a great way to have two separate projects with the same files but targeting different frameworks. Specifically, I'm building a library that needs to work with both the compact framework and the normal framework - file links makes it super easy. I wish it was possible to add a whole folder as a link.
Solution Folders
I've known about solution folders for a while, but I find myself using them more and more. It keeps solutions nice and tidy. I'll typically have 3 solution folders - one that has all 3rd party assemblies, one for any test clients projects, and one for unit test projects.
Default File Templates
This is something you do once and forget about, but I once again changed some of the default templates used by visual studio. For example, the default file template whenever you add a new Class is:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
Which I like to change to:
namespace $rootnamespace$
{
using System;
public class $safeitemrootname$
{
}
}
In 2008 (you should be able to find it relatively easy in older versions), you can change the default templates by poking around in:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\
RhinoMocks
Since I've been writing a lot of unit tests, I've also been getting more and more familiar with RhinoMocks. Somehow, I had never had to record an expectation against a property's Setter before. Turns out all you need to do is call the setter with the expected value while recording. Here's what it might look like:
using (_mocks.Record())
{
_somePartial.Age = 10;
}
using (_mocks.Playback())
{
_ somePartial.Birthday = DateTime.Now.AddYears(-10);
}
_mocks.VerifyAll();
I've also written a couple custom constraints to keep things readable and simple.
Versioning
The system I'm working on has extreme versioning requirements. Most of the time when Update is called on an object we don't actually update the object. Instead, we create a new version and set its Parent property to the first instance ever created for that object. What makes it tricky is that some fields trigger this behavior while others simply cause the object to be updated. Still trying to work out a reusable system.