ChrisCScott / forecaster

A personal finances forecasting tool for Canadian retirement planning
Other
1 stars 2 forks source link

DebtPaymentStrategy methods return values and mutate arguments #48

Closed ChrisCScott closed 6 years ago

ChrisCScott commented 6 years ago

DebtPaymentStrategy._assign_available and DebtPaymentStrategy._assign_minimums each return a scalar (the amount of savings consumed) and mutate an input (transactions). The usual style guidance for Python is to either return a value or mutate (c.f. https://stackoverflow.com/questions/26027694/correct-style-for-python-functions-that-mutate-the-argument), and to only mutate the leftmost input.

Consider how to address this in the context of these methods. Since they are underscored (quasi-private) methods, consider returning a tuple of (available_consumed, further_transactions). (Note: this, in combination with using dict.get(key, default), will help make the logic of these methods cleaner, since there's no need to fill out the keys.) Calling methods will need to add the further_transactions to their transactions dict, which might be a bit slower than mutating, but it will be clearer for reading and debugging.

Suggested method signature: _assign_available(debt: Debt, transactions: dict[Debt, Money], when: Decimal) -> (Money, dict[Debt, Money])