Created
January 28, 2017 03:34
-
-
Save jdh30/b01279a6be91467c5887b72a7c2f303e to your computer and use it in GitHub Desktop.
My solution to the Cleaner Code challenge (https://www.codeproject.com/articles/1083348/csharp-bad-practices-learn-how-to-make-a-good-code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AccountKind = Simple | Valuable | MostValuable | |
type CustomerStatus = | |
| Unregistered | |
| Registered of AccountKind * Years:int | |
let accountFactor kind = | |
match kind with | |
| Simple -> 0.9m | |
| Valuable -> 0.7m | |
| MostValuable -> 0.5m | |
let loyaltyFactor years = | |
1m - decimal(min years 5) / 100m | |
let applyDiscount price status = | |
match status with | |
| Unregistered -> price | |
| Registered(kind, years) -> | |
price * accountFactor kind * loyaltyFactor years |
I vote
Registered of (AccountKind, Years: int)
the same way its called later Registered(kind, years)
also make
price * accountFactor kind * loyaltyFactor years
into
price * accountFactor(kind) * loyaltyFactor(years)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great job with the refactoring. Seeing examples like this make me want to look into F#... but then I see this and it drives me nuts:
Registered of AccountKind * Years:int
I am really curious about the thought process of whoever came up with that, instead of the much more obvious
Registered: AccountKind, Years: int
or
Registered of AccountKind, Years of int