I'm writing a new package in Go, to work with money (I'm aware that other packages already do this).
An essential type is Money:
type Money struct {
// Factional value of the monetary value.
Cents int
// ISO code of the currency of the monetary value.
Currency string
bank *Bank
}
Now I have to define a method m.ExchangeTo(currency) that exchanges money to another currency.
The question is: what is the best signature for this method?
Some proposals:
Receiver and return value are pointers
func (m *Money) ExchangeTo(toCurrency string) *Money
Receiver and return value are structs
func (m Money) ExchangeTo(toCurrency string) Money
No return value, ExchangeTo change the receiver value (side effect)
func (m *Money) ExchangeTo(toCurrency string)
I know this depends on what you have to do, but this is a general-purpose package, so I'm looking for some advice.