I've found recently that for some types of financial calculations that the following pattern is much easier to follow and test especially in situations where we may need to get numbers from various stages of the computation.
public class nonsensical_calculator
{
...
double _rate;
int _term;
int _days;
double monthlyRate { get { return _rate / 12; }}
public double days { get { return (1 - i); }}
double ar { get { return (1+ days) /(monthlyRate * days)
double bleh { get { return Math.Pow(ar - days, _term)
public double raar { get { return bleh * ar/2 * ar / days; }}
....
}
Obviously this often results in multiple calls to the same accessor within a given formula. I was curious as to whether or not the compiler is smart enough to optimize away these repeated calls with no intervening change in state, or whether this style is causing a decent performance hit.
Further reading suggestions are always appreciated