indy alt.net - team roles fishbowl

October 16th, 2008

We’re having another Indy Alt.Net (www.indyalt.net) meeting tonight!

The topic is on team roles. We’re planning on having a

  • BA - Sorry A-Team fans, this is a Business Analyst, not Mr. T
  • Developers - All who serve at different levels in their own organizations
  • PM - [Hopefully] If you’re a PM, and can come, please do, we need you!

The goal is really just to have good conversation about different roles in different organizations so we can all learn something by the way other organizations behave.

As usual, free pizza and networking starting at 5:15, with the talk starting at 6:00.

Logistics:
Tonight (October 16)
6:00P - 8:00P (food and networking at 5:15)
Ivy Tech near Fall Creek and Meridian on the north side of Fall Creek
Auditorium, 4th Floor 50 W Fall Creek Pkwy North Dr
Indianapolis, IN 46208
Map

Hope to see you there!

reflection

October 3rd, 2008

It being a day or several (depending on when this gets published) after my birthday, it seems like a good time to reflect, and to set some goals for the upcoming short-term (~year).

The list is not all about technical stuff.  It is really stemmed from some things God has laid in front of me lately.

Becoming a message

Our pastor shared a great quote with our church last weekend that really stood out to me.

…my life is my message  - Gandhi

What would my message be if someone asked me today?
What would my message be if someone asked you today?
What would your message be if someone asked you today?

I’m guessing there will be more about this coming soon.

Continuous Improvement

This area is far more about you than it is about me.  Sure, I have much to learn, have a long list of areas of which I’d like to personally continue to improve.I feel a great need to help my colleagues, help my company, and help my community.  Something tells me I’m in a unique position to make an impact on each.So here is a list of areas I’d like to improve (in to particular order):

  • Technical Breadth
  • Technical Depth
  • Leadership Skills
  • Management Skills
  • Physical Health
  • Faith
  • Creativity
  • Being a better husband
  • Brewing better coffee

Back to Basics

I’m a firm believer in fundamentals.  I’d like to re-explore what the core fundamentals of the industry are, and find out where I need to brush up/start over/start (for the first time).

Okay… enough for now.  Stay tuned.

IndyTechFest PocketMod

October 1st, 2008

It’s October in Indy (well, most other places too), so that means time for IndyTechFest.

For those of you that read this, or find this, I’ve put together a PocketMod for the session schedule.  IMO, the UI is easier to use than the mini poster.  I’m sharing so you can have one too!

Here it is:  IndyTechFest PocketMod

Here is how I did it:

  • Used Word to create this: PocketMod source
  • Used the Office 2007 PDF Publisher to publish it to a PDF
  • Used the PDFtoPocketmod converter app to convert the 8-page PDF to a 1-page PDF with all the pages squished and arranged just right
  • Printed, and trimmed the margins with a paper cutter
  • Folded and snipped, via the video at Pocketmod.

Super simple, super awesome.

a generic one-to-one mapping class

September 17th, 2008

Another “tip/trick” style post, but thought it may prove useful to someone (or so I can find it again later!)…

Sometimes I find myself needing to map instances/values of one type to another.  For example, on my current project we have an enumeration in our communications layer, and a VERY similar one in the domain layer.  The reason for this is so we don’t have to be referencing the communications layer version all over in the domain code.  So, there is naturally a one to one mapping between these enumerations.

Consider the following enumerations:

enum Polygons
{
    Triangle,
    Rectangle,
    Pentagon,
    Other
}

enum NumSides
{
    Three,
    Four,
    Five,
    More
}

This is the code I usually write to solve this problem:

private Polygons MapShapes( NumSides sides )
{
    switch( sides )
    {
        case NumSides.Three:
            return Polygons.Triangle;
        case NumSides.Four:
            return Polygons.Rectangle;
        case NumSides.Five:
            return Polygons.Pentagon;
        case NumSides.More:
            return Polygons.Other;
        default:
            throw new NotSupportedException(
                string.Format( "Mapping to Polygons from NumSides value {0}
                    is not supported", sides.ToString() ) );
    }
}

private NumSides MapShapes( Polygons polygon )
{
    switch( polygon )
    {
        case Polygons.Triangle:
            return NumSides.Three;
        case Polygons.Rectangle:
            return NumSides.Four;
        case Polygons.Pentagon:
            return NumSides.Five;
        case Polygons.Other:
            return NumSides.More;
        default:
            throw new NotSupportedException(
                string.Format( "Mapping to NumSides from Polygons value {0}
                    is not supported", polygon.ToString() ) );
    }
}

It turns out we had 3 said enumerations.  So picture the above, copied 3 times.  This thing was just begging for abstraction!

I came up with a Generic (proper) Map class that you can add mappings to and retrieve the corresponding mapped value of the other type… both directions.  Here is the implementation:

public class Map
{
    private Dictionary _oneToTwo;
    private Dictionary _twoToOne;

    public Map()
    {
        _oneToTwo = new Dictionary();
        _twoToOne = new Dictionary();
    }

    public Map Add( Type1 value1, Type2 value2 )
    {
        _oneToTwo.Add( value1, value2 );
        _twoToOne.Add( value2, value1 );
        return this;
    }

    public Type1 this[Type2 value]
    {
        get
        {
            if( !_twoToOne.ContainsKey( value ) )
            {
                throw new NotSupportedException(
                    string.Format( "Mapping from type {0} to type {1} with
                                    value {2} is not defined",
                        typeof( Type2 ).Name,
                        typeof( Type1 ).Name,
                        value.ToString() ) );
            }
            return _twoToOne[value];
        }
    }

    public Type2 this[Type1 value]
    {
        get
        {
            if( !_oneToTwo.ContainsKey( value ) )
            {
                throw new NotSupportedException(
                    string.Format( "Mapping from type {0} to type {1} with
                                    value {2} is not defined",
                        typeof( Type1 ).Name,
                        typeof( Type2 ).Name,
                        value.ToString() ) );
            }
            return _oneToTwo[value];
        }
    }
}

And, here it is in action:

Map<NumSides, Polygons> shapeMap = new Map<NumSides, Polygons>()
                                    .Add( NumSides.Three, Polygons.Triangle )
                                    .Add( NumSides.Four, Polygons.Rectangle )
                                    .Add( NumSides.Five, Polygons.Pentagon )
                                    .Add( NumSides.More, Polygons.Other );

// shape1 value is Polygons.Rectangle
Polygons shape1 = shapeMap[NumSides.Four]; 

// shape2 value is NumSides.Three
NumSides shape2 = shapeMap[Polygons.Triangle];

This not only works with enumerations, but any type.  I see an extension to this possibly allowing for a default mapping, and possibly constraining Type1 and Type2 to be IComparable or something like that as well, so you can have more control over your matching than whatever the default matching behavior that the Dictionary uses is.

That’s it… enjoy!

looking for a better switch/case statement?

September 4th, 2008

I find myself sometimes wishing I had a better switch/case construct in C#.

My requirements of “better” are:

  • Case statements are automatically scoped
  • I can switch on more than simple types
  • I can have custom logic for my matching criteria

But why not just use if/else if/else…?

Good question, I’m glad you asked! However, I don’t have an excellent answer other than personal preference. if/else if/else is okay sometimes, but other times I have a deterministic set of conditions, and a switch type construct feels more symmetrical to me. I loves me some symmetric feeling code, it just feels cleaner somehow.

So I’ll present a somewhat contrived example just so you can see what the usage looks like, then we’ll see the code.

Usage


public void DoSomething()
{
	object foo = new object();
	object bar = new object();
	object baz = new object();

	Switch<object>.On(baz)
		.Case(x => x.Equals(foo), () =>
		{
			Console.WriteLine("came into foo case");
		})
		.Case(x => x.Equals(bar), () =>
		{
			Console.WriteLine("came into bar case");
		})
		.Default( () =>
		{
			Console.WriteLine("came into default case");
		})
		.Go();
}

The output from the above, is as you’d expect, the default case, since baz wasn’t equal to foo or bar.

Implementation


public class Switch<T>
{
	private T _target;
	private List<KeyValuePair<Predicate<T>, Action>> _cases;
	private Action _default;

	public static Switch<T> On(T target)
	{
		return new Switch<T>(target);
	}

	public Switch(T target)
	{
		_target = target;
		_cases = new List<KeyValuePair<Predicate<T>, Action>>();
	}

	public Switch<T> Case(Predicate<T> @case, Action action)
	{
		_cases.Add(new KeyValuePair<Predicate<T>, Action>(@case, action));
		return this;
	}

	public Switch<T> Default(Action action)
	{
		_default = action;
		return this;
	}

	public void Go()
	{
		foreach(var @case in _cases)
			if (@case.Key(_target))
			{
				@case.Value();
				return;
			}
		if (_default != null)
			_default();
	}
}

The only part I don’t really like is having to kick it off with the Go() at the end. Any ideas for a better way to kick it off, or at least a better name for it (instead of Go).

Feedback? Ideas?

Update

Paul had a great idea a couple great ideas (see comments) on how to get rid of the Go() at the end, and to force Default to only appear at the end. Here is the new implementation. Usage is the same, just remove the Go().


public class Switch<T>
{
	private T _target;
	private bool _alreadyMatched;

	public static Switch<T> On(T target)
	{
		return new Switch<T>(target);
	}

	public Switch(T target)
	{
		_target = target;
		_alreadyMatched = false;
	}

	public Switch<T> Case(Predicate<T> @case, Action action)
	{
		if (!_alreadyMatched && @case(_target))
		{
			_alreadyMatched = true;
			action();
		}
		return this;
	}

	public void Default(Action action)
	{
		if (!_alreadyMatched)
		{
			_alreadyMatched = true;
			action();
		}
		return this;
	}
}

chrome… c’mon

September 3rd, 2008

So I did what every other self-respecting geek has done in the past couple days… downloaded and installed chrome.  I love my firefox experience at the moment (I have the exact add-ons/plugins I want/need to make browsing pleasurable and fast), but I thought I’d give it a shot.

However, I was greeted with this (and I can’t seem to get anything other than this at the moment).  Yes, I tried pressing reload or going to another page… didn’t work.

image

That flat-out stinks (not because I personally can’t use it, but because I’ve got no idea what to do to fix it, or what went wrong).  Do I have to restart first?  Do I have to install some WebKit thing first?  Do I have to <insert other thing I shouldn’t have to do here> first?

Maybe I’m just clueless, but this was a bad first impression.

tfs - using winmerge as your merge/diff tool

August 26th, 2008

If you’re used to using something like winmerge with your SCM of choice, if you wind up using TFS, the built-in diff/merge tools can leave much to be desired.

Here is how to change the tool VS 2kX uses to do diffs/merges when hooked up to TFS (note that these are my settings for using winmerge for ALL file types):

Go To: Tools/Options/SourceControl/Visual Studio Team Foundation Server/Configure User Tools

Click “Add…”
Extension:  .*
Operation: Compare
Command: C:\Program Files\WinMerge\WinMergeU.exe
Arguments: /e /wl /dl %6 /dr %7 %1 %2
Click “Add…”

Extension:  .*
Operation: Merge
Command: C:\Program Files\WinMerge\WinMergeU.exe
Arguments: /ub /dl %6 /dr %7 %1 %2 %4

The winmerge command line reference can be found here.

tfs - error exporting queries to excel

August 26th, 2008

Starting my new project in a new role, as project lead, I need to be managing things in TFS.  The UI for batching these things up is nonexistent, but there is Excel integration so you can do it all in Excel, hit save, and it all goes back to the TFS server… pretty slick I must say (I was actually in the midst of writing such a tool when I realized this functionality already existed OOB).

However, the first time I tried to use this functionality… BLAM, I get smacked with this:

TF80042: The document cannot be opened because you do not have Microsoft Excel 2003 or later, or one of its components installed. For more information, see the Team Foundation Installation Guide.

Isn’t that teh suck?

Anyways, there is a sweet write-up on how to fix it here: http://blogs.microsoft.co.il/blogs/srlteam/archive/2007/07/17/Error-when-trying-to-export-queries-to-Excel.aspx.

Thanks Elad!

Going Medieval on Your App with Castle MonoRail - Indy ALT.NET

August 22nd, 2008

So last night I gave a talk at Indy ALT.NET on Castle MonoRail.  It was really just a sort of intro to MonoRail type of deal, but the cool part was that we held a Dojo after I got done jabbering.

We ended up building a Poll Generator for our dojo activity.  We almost got done in the 45 minutes or so that we dojo’d.  It was a pretty fun activity, and I’d like to do it again sometime soon.

Also, this was really my first public speaking engagement to our technical community, and let me say it was a blast.  Everyone had great things to say, and many great questions were asked too.

I set up a google code repository so you can grab my slidedeck and grab the source for our dojo activity and my demo app.

Maybe next time I’ll post before the talk, so I can let people know about it.

Thanks guys for all the great feedback, and thanks to my wife for understanding why I wasn’t spending any of my evenings with her this week!

singly implemented interface… addendum

August 22nd, 2008

Wowza!  So I’ve begun reading LosTechies (tons of great content, highly recommended!), and came across a passage today from Jimmy Bogard, who says what I feel, but what I couldn’t get out of my head:

On a sidenote, it always bothered me when people say that an interface with one implementation is a design smell.  No, an interface is used to expose a contract.  Interfaces communicate design intent, far better than a class might.

Exactly!