Karl Seguin

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
What's Up Doc

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.


Posted Sat, Sep 6 2008 11:49 AM by karl

[Advertisement]

Comments

Bryan Reynolds wrote re: What's Up Doc
on Sat, Sep 6 2008 1:48 PM

What do you think of TypeMock?

karl wrote re: What's Up Doc
on Sat, Sep 6 2008 2:48 PM

@Bryan:

All I know is that I have to pay to use it for a commercial system (well, also that it can mock statics). I could use it for my open source projects, but then that means using two different mocking frameworks..not ideal

Joshua Flanagan wrote re: What's Up Doc
on Sat, Sep 6 2008 3:59 PM

When you say you have a solution folder for 3rd party assemblies - do you mean their source code, or the compiled binaries? I've seen people include binaries in their VS solution before and never knew why - maybe you can explain it?

Kevin Pang wrote re: What's Up Doc
on Sun, Sep 7 2008 5:25 AM

I'm making an effort as well to get Twitter to become a more useful tool (rather than the one-way dialog it feels like now).

I'm finding that StackOverflow is becoming what I wanted Twitter to be: a quick and easy way to get answers to programming questions from those in the same line of work as me.

Colin Jack wrote re: What's Up Doc
on Sun, Sep 7 2008 6:58 AM

On versioning, you looked at Martin Fowler's patterns for versioning objects or event messages. Greg Young's approach also seems like it might be useful for your sort of situation, dunno though. Be very interested in reading more about what you come up with.

Dew Drop - September 7, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - September 7, 2008 | Alvin Ashcraft's Morning Dew
on Sun, Sep 7 2008 3:04 PM

Pingback from  Dew Drop - September 7, 2008 | Alvin Ashcraft's Morning Dew

Josh Einstein wrote re: What's Up Doc
on Mon, Sep 8 2008 11:01 PM

Here's a tip for managing your custom templates across multiple machines (or just so you don't have to remember to back it up if you reinstall Windows or get a new computer)

Using Vista, create a symbolic link pointing the built-in template folder to a Live Mesh or Foldershare location. I have a folder C:\Development\Templates and I use a symbolic link to point Visual Studio to that folder.

I used to mess around with trying to change the registry or settings files but now I just have a single batch file that sets up all the symbolic links pointing various default folders to my custom locations.

mklink /d "program files\blah" "c:\development\templates\builtin"

Brian J wrote re: What's Up Doc
on Tue, Sep 9 2008 6:47 AM

What's the other type framework do you use?  We use PostSharp for the main-application and Typemock for testing.

Works well for us because the one is a static weaver which we want on application code, but then Typemock is dynamic which works great because we don't have to code for the testing framework (why we don't use RM), we just code for testability alone.

Having 2 tools was only a minor speed bump and has actually proven to be useful for us - don't dismiss it too quickly.

karl wrote re: What's Up Doc
on Tue, Sep 9 2008 5:41 PM

Brian J:

I *don't* use two. That's the point, I don't want to. Use RhinoMocks for commercial projects, and TypeMock for open source ones? No thanks.

Manoj Waikar wrote re: What's Up Doc
on Thu, Oct 9 2008 12:44 PM

Hi Karl,

It might be a dumb question, but I changed the Class.cs file in the Class.zip file, in the folder "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033" folder to get a modified template, but it doesn't work.

When I add a new class, VS still generates the definition based on the old template. Any idea why?

Thanks and regards,

Manoj.

karl wrote re: What's Up Doc
on Thu, Oct 9 2008 9:09 PM

Manoj:

Try checking out your the ItemCache, I think templates are cached there and that might be what you're saying. Not 100% sure though:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache

Manoj Waikar wrote re: What's Up Doc
on Fri, Oct 10 2008 11:52 AM

Thanks Karl, that worked :)

And thanks for the "Foundations of Programming" e-book too, it had some real practical guidance.

Regards,

Manoj.