Stephen A. Fuqua (saf)

a Bahá'í, software engineer, and nature lover in Austin, Texas, USA

Think For One ... Second

What’s wrong with this code? There are unnecessary lines. So? Why care about unnecessary lines? Because it shows that the programmer was not really thinking about what he was doing.

MyObject obj = someList.Find(delegate(MyObject test)
{
    if (test.Id.Equals(packageId))
    {
        return true;
    }
    else
    {
        return false;
    }
});

We always need to be thinking carefully about even little things like this, if we want to produce quality code. Thankfully in the sense that I mean “thinking carefully” it is something we can develop into habits, rather than having to stop and consciously think carefully. One way to write this more simply:

MyObject obj = someList.Find(delegate(MyObject test)
{
    return test.Id.Equals(packageId);
});

Posted with : Tech, Microsoft .NET Framework, General Programming