Ayende @ Rahien

Refunds available at head office

It depends on what you are optimizing for…

Today I was writing this code:

public class FakeRandomValueGenerator : IRandomValueGenerator
{
    private readonly int valueToReturn;

    public FakeRandomValueGenerator(int valueToReturn)
    {
        this.valueToReturn = valueToReturn;
    }

    public int Next(int min, int max)
    {
        return valueToReturn;
    }
}

This caused some concern to my pair, who asked me why I was hand rolling a stub instead of using a mocking framework. My answer was simple.

It will take me less time to write the class than it would take me to bring up the Add Reference dialog.

Comments

James
03/25/2009 01:34 AM by
James

Too true!

I typically schedule my reference adding around getting a cup of coffee.

Jim Greco
03/25/2009 01:40 AM by
Jim Greco

How about....

public class RandNum

{

public Func

<int RandFunc { get; set; }

public int Next(int min, int max)

{

    return RandFunc != null ? RandFunc() : Random.Next(min, max);

}

}

syntax may be horribly off :)

junior programmer
03/25/2009 01:48 AM by
junior programmer

doesn't this mean we should ditch visual studio for something more lightweight and faster

unfortunately m$ always try to bundle everything into one product and try to generate everything on the fly

i still prefer not to use IDE

i prefer things like textmate, vim, etc

jdn
03/25/2009 01:55 AM by
jdn

LOL. Awesome.

Jacob Stanley
03/25/2009 04:03 AM by
Jacob Stanley

If only IRandomValueGenerator were a delegate instead of an interface:

int random = 6;

var c = new ClassThatNeedsRandomValues((min, max) => random);

Thamil
03/25/2009 07:51 AM by
Thamil

You've become complete freak man!! This is good.

dave
03/25/2009 01:38 PM by
dave

If this is the only stub you need, makes sense. Otherwise, not.

Jose
03/25/2009 04:51 PM by
Jose

Add Reference dialog is so slow !!!! that I was thinking why don't put four options outside:

-Add Project Reference

-Add File Reference

-Add Gac Reference

-Add Com Reference

The last two are the slow ones.

¿thougs? HEY? Someone that want to put a LADY-BUG

Will Smith
03/25/2009 07:16 PM by
Will Smith

R# is pretty good about adding new references for you without having to open the "Add Reference" dialog.

Stefan Steinegger
03/25/2009 09:03 PM by
Stefan Steinegger

I always have two or three instances of visual studio running at the same time. If one is compiling, running tests, blocked for no reason or about to crash, I'm working with the other one on something else. In other words, I'm switching every few minutes. :-/

Yes, I'm also an impatient person.

Patrik H&#228;gne
03/25/2009 09:31 PM by
Patrik Hägne

I did the exact same thing (well it was a different interface) for the exact same reason a couple of days ago. To my dismay I had to do something else in another test a couple of minutes later that forced me to go and add the reference anyway.

Chris Smith
03/26/2009 12:09 AM by
Chris Smith

Use it as a couple of minutes to chill out and find something interesting to listen to...

Or do what I did and rewrite everything so it builds in nant straight out of SVN with just the SDK on the box. There are SO many problems relying on Visual Studio for even basic tasks sometimes.

Comments have been closed on this topic.