News for hackers. Stuff that matters.
Re:Your DI framework is killing your code by atemerev on Tuesday September 29, 2015 @08:58AM (#10295871)
For example?
Re:Your DI framework is killing your code by mistermann on Tuesday September 29, 2015 @10:06AM (#10296356)
Couldn't you just add a new SendMethod optional parameter defaulted to the method that was used prior to the refactoring? No breaking API changes, no extensive manual refactoring of the entire codebase, as far as I can tell. This is how I always did refactoring for years, it's immediately obvious to support developers wtf is going on, and there's no requirement to have any "complicated" architecture on every single object in your entire application. Instead, the code largely resembles the simplicity of the real world being modeled.

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.

Re:Your DI framework is killing your code by anton_gogolev on Tuesday September 29, 2015 @10:31AM (#10296524)
> Couldn't you just add a new SendMethod optional parameter

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.

Re:Your DI framework is killing your code by mistermann on Tuesday September 29, 2015 @11:40AM (#10297084)
Holy cow it seems it seems you're right:

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.

Re:Your DI framework is killing your code by throwawaykf05 on Tuesday September 29, 2015 @09:05AM (#10295931)
I suppose you could add more methods, e.g sendEmailViaMailGun. But that results in the invoker having to have if-else logic (itself a code smell) for selecting which method to call, which is bad for SRP. You could try to fix that by encapsulating that logic into an EmailRouterStrategy class, but that's just another dependency you have to inject, which is not ideal according to TFA.
Re:Your DI framework is killing your code by anon1385 on Tuesday September 29, 2015 @09:05AM (#10295929)
A 'sending mechanism' property on the email object that defaults to SMTP?
Re:Your DI framework is killing your code by smanzer on Tuesday September 29, 2015 @10:36AM (#10296576)
This. There may be other reasons to dislike the email.send() formulation, but it seems like the need to support other mail APIs could be handled relatively easily within this type of OO approach through the use of default values.
Re:Your DI framework is killing your code by to3m on Tuesday September 29, 2015 @09:02AM (#10295904)
"GetMailPolicySingleton()->SetSendingMechanism(Email::SMTP)" ;)
Re:Your DI framework is killing your code by rescripting on Tuesday September 29, 2015 @09:54AM (#10296270)
Sometimes you're sending via SMTP, sometimes via MailGun. If you don't remember to call GetMailPolicySingleton()->SetSendingMechanism() before every email.send() you end up using whatever policy was set last.
Re:Your DI framework is killing your code by taspeotis on Tuesday September 29, 2015 @10:18AM (#10296440)
> Singleton

What if two threads need to send mail via SMTP and Mailgun...

Re:Your DI framework is killing your code by anton_gogolev on Tuesday September 29, 2015 @10:29AM (#10296511)
Singletons have nothing to do with reentrancy or lack thereof.