Skip to content

Instantly share code, notes, and snippets.

@eldavido
Last active January 17, 2018 16:37
Show Gist options
  • Save eldavido/78d6ed17a58bf2421c11d263b483e44b to your computer and use it in GitHub Desktop.
Save eldavido/78d6ed17a58bf2421c11d263b483e44b to your computer and use it in GitHub Desktop.
Code debt example
// 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