Only if you decide to change the signature, there are other ways to achieve the same result.
Only if you decide to change the signature, there are other ways to achieve the same result.
(let ((*emailer* mailgun-client))
(send email))
Or, using Go contexts (which are just a way of hacking in dynamic variables): ctx = email.NewContext(ctx, mailgunClient)
email.Send(ctx)
And in email.Send: emailer, ok := EmailerFromContext(ctx)
if !ok {
emailer = defaultSMTPEmailer
}What if two threads need to send mail via SMTP and Mailgun...
Is this approach is so dangerous (as we're constantly told) why has it never caused me any problems? Maybe I'm missing something but I've never read an article that explains what it is I'm missing in a way that clicks.
Adding an optional parameter to an already existing method is not always a backwards-compatible change. For example, in C# this will effectively change method signature and break API.
http://haacked.com/archive/2010/08/10/versioning-issues-with...
http://haacked.com/archive/2010/08/12/more-optional-versioni...
...yet I've used this technique for years in VB.Net without issue....weird.