In fact, I'm a little overwhelmed by the gentleman regarding data quality. Unfortunately, the colloquial term “percent” can mean one of two different things: probability and deviation. The OP does not indicate which, but since the variance is usually calculated, I assume that it can mean percent as probability or fraction (e.g., discount).
a very good reason to write the Percentage class for this purpose has nothing to do with the presentation, but so that you do not allow these silly stupid users to do something like entering invalid values such as -5 and 250.
What I think most about is the Probability class: a numeric type whose valid range is strictly [0,1]. You can encapsulate this rule in ONE place, and not write such code in 37 places:
public double VeryImportantLibraryMethodNumber37(double consumerProvidedGarbage) { if (consumerProvidedGarbage < 0 || consumerProvidedGarbage > 1) throw new ArgumentOutOfRangeException("Here we go again."); return someOtherNumber * consumerProvidedGarbage; }
instead, you have this nice implementation. No, this is not a fantastically obvious improvement, but remember that you perform this value check every time you use this value.
public double VeryImportantLibraryMethodNumber37(Percentage guaranteedCleanData) { return someOtherNumber * guaranteedCleanData.Value; }
Michael blackburn
source share