Last active
January 17, 2018 16:37
-
-
Save eldavido/78d6ed17a58bf2421c11d263b483e44b to your computer and use it in GitHub Desktop.
Code debt example
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
// Bad version | |
protected DollarCents Calculate() { | |
var x = Events.OfType<CardSaleAttached>().Select(e => e.Sale) | |
.Aggregate(DollarCents.Zero, (a, b) => a + b.SecuredMoney()); | |
var y = Events.OfType<FolioPaymentReceived>() | |
.Aggregate(DollarCents.Zero, (a, b) => a + b.Amount); | |
return x + y; | |
} | |
// Good version | |
protected DollarCents GetCurrentIrrevocableTenderAmount() { | |
var cardTenders = Events.OfType<CardSaleAttached>().Select(e => e.Sale) | |
.Aggregate(DollarCents.Zero, (total, sale) => total + sale.SecuredMoney()); | |
var cashAndCheckTenders = Events.OfType<FolioPaymentReceived>() | |
.Aggregate(DollarCents.Zero, (total, payment) => total + payment.Amount); | |
return cardTenders + cashAndCheckTenders; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment