Rants, rambles, news and notes from another geek

NUnit Assert.AreEquals Parameter Ordering

I regularly take jabs at my boss Jim Newkirk&nbsp_place_holder;(original author of NUnit 2.x), telling him, “I think you put the parameters to AreEqual in the wrong order. It should be&nbsp_place_holder;actual, expected and not the other way ‘round.”

To which he consistently replies, “Well, you would be wrong.”

But all kidding aside, I still find myself writing code that assumes the AreEqual method has the opposite ordering.

It comes from the way I write if() statements. I write them like this:

if( myVariable == 4 )
{
  // Do something
}

&nbsp_place_holder;I have seen C/C++ programmers do this…

if( 4 == MyVariable )
{
  // Do something
}

ΓǪas a way to protect themselved from forgetting the second = symbol (in fact I used to do it too).&nbsp_place_holder;But as the C# compiler won’t let me make that mistake, I don’t do it anymore.

Which is why I want to write…

Assert.AreEqual( myVariable, 4 );

…instead of…

Assert.AreEqual( 4, myVariable );

But apparently, I’m wrong. But I still type it the other way more often than not.

Now playing: Bob Marley & The Wailers - Misty Morning