Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • I'm thankful for this point of view. In this specific case, I was writing functionality into a fairly new microservice. Unfortunately, even in our main codebase, while we do have some of the above in use, none of it is really in a remotely reusable way. Everything that needs to be reusable ended up in some static class or it's just copy and pasted around the code. I do think I've still been going a bit far, but I do agree that not everything needs to be completely dissected and decoupled. Commented Jul 11, 2019 at 2:42
  • @JDDavis I was trying to write something different from the other answers (which I mostly agree with). Whenever you copy&paste something, you're preventing reuse as instead of generalizing something you create another non-reusable piece of code, which will force you to copy&paste more one day. IMHO it's the second biggest sin, just after blindly following rules. You need to find your sweet spot, where following rules makes you more productive (especially w.r.t. the future changes) and occasionally breaking them a bit helps in cases when the effort wouldn't be inappropriate. It's all relative. Commented Jul 11, 2019 at 3:25
  • @JDDavis And everything depends on the quality of your tools. Example: There are people claiming that DI is enterprisey and complicated, while I'm claiming that it's mostly free. +++ Concerning breaking the rules: There are four classes, I need in places, where I could only inject them after a major refactoring making the code more ugly (at least for my eyes), so I decided to make them to singletons (a better programmer might find a better way, but I'm happy with it; the number of these singletons haven't changes since ages). Commented Jul 11, 2019 at 3:37
  • This answer expresses pretty much what I was thinking when the OP added the example to the question. @JDDavis Let me add that you may save some boilerplate code/classes by using functional tools for the simple cases. A a GUI provider, for example - instead of introcuding a new interface a new class for this, why not just utilize Func<Guid> for this, and inject a anonymous method like ()=>Guid.NewGuid() into the constructor? And there is no need to test this .Net framework function, this is something Microsoft has done for you. In total, this will save you 4 classes. Commented Jul 11, 2019 at 6:41
  • ... and you should check if the other cases you presented can be simplified the same way (probably not all of them). Commented Jul 11, 2019 at 6:42