Welcome to MSDN Blogs Sign in | Join | Help

Naming Direct Output Variables

In my series of Zero-Friction TDD tips and tricks, it's time to look at naming Direct Output variables.

[TestMethod]
public void DoStuffWillReturnMessage()
{
    // Fixture setup
    string expectedResult = "ploeh";
    MyClass sut = new MyClass();
    // Exercise system
    string result = sut.DoStuff(expectedResult);
    // Verify outcome
    Assert.AreEqual<string>(expectedResult, result, "DoStuff");
    // Teardown
}

As you can see, I use the name result for the return value of DoStuff, and I always use that word, irrespective of its type or other circumstances. Whether you prefer result or another word is not important; the salient point is that by always using the same word, you save a context switch (because you don't have to stop and think of a good name) and thereby incrementally increase your productivity.

Published Friday, November 14, 2008 10:38 AM by ploeh

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# ploeh blog : Zero-Friction TDD

Tuesday, November 18, 2008 5:10 AM by ploeh blog : Zero-Friction TDD

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker