Is a Useful Refactoring?

I have a method that looked like this:

public override float EvaluatePercentComplete(MeasurementTrigger trigger)
{
    int range = (DateTime.Today.Subtract((DateTime)trigger.LastValue).Days);
    int total = ((int)trigger.TriggerValue);
    if (total == 0) throw new ArgumentOutOfRangeException("total", "The total value denominator is zero");
    return Convert.ToSingle(range / total);
}

But, I ended up refactoring it like this:

public override float EvaluatePercentComplete(MeasurementTrigger trigger)
{
    if (((int)trigger.TriggerValue) == 0) throw new ArgumentOutOfRangeException("total", "The total value denominator is zero");
    return Convert.ToSingle((DateTime.Today.Subtract((DateTime)trigger.LastValue).Days) / ((int)trigger.TriggerValue));
}

Is that a useful refactoring?  After all, it is a complicated division, and is untested code as of now.  But, I remember reading Martin Fowler's comments about avoiding the declaration of variables when possible; he found that it was often just as quick to perform the conversion directly and use the object instead.  But, to really know if it is a performance problem requires some sort of profiling tool at the end of the process.

I leave the final word up to you...

Comments

No Comments