Geek Noise
Rants, rambles, news and notes by Peter Provost
27

NUnit Assert.AreEquals Parameter Ordering

Thursday, 27 January 2005 05:46 by Peter Provost

I regularly take jabs at my boss Jim Newkirk (original author of NUnit 2.x), telling him, “I think you put the parameters to AreEqual in the wrong order. It should be 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
}

 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). 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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Technology
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed