How to increase readability of an interface (C#)
-
@asdf said in How to increase readability of an interface (C#):
No, because all
mostof the time, patterns are misused because they're applied incorrectly
-
@asdf said in How to increase readability of an interface (C#):
@Dreikin Okay, but that just looks like the standard stuff that every ORM does to me. How would you write more complicated queries involving JOINs, like the following (example from the SQLAlchemy docs)?
I dunno how a design patterns fan would do it, but I'd just make a partial class off the EF class and put my custom shit in there.
-
@asdf NEEDS MOAR FP.
-
@Captain I knew you'd downvote me
-
@asdf Let's cry together.
-
@Captain you shouldn't, that would be a side effect, and side effects are the devil, right?
-
-
@Captain said in How to increase readability of an interface (C#):
Making @asdf cry was totally necessary.
Next time, can you at least make me cry inside a Monad, where I'm encapsulated properly and no-one else can see me?
-
DI is built into ASP.NET Core. That's in addition to the MEF (Microsoft Extensibility Framework).
In Java, Spring Framework (the basis of the widely used Spring Web and Spring Web MVC frameworks) is a DI framework.
Edit: Well, technically MEF and Spring are IOC, but DI is one of the ways to implement IOC.
-
@flabdablet said in How to increase readability of an interface (C#):
Best comment on that page:
TLDR; “Screwdrivers suck, everyone should use hammers”.
That's also what most of this thread's discussion has degenerated into, which is totally dumb. Most of good software development can be summed up as:
- Have many tools.
- Use the right tool.
-
@powerlord The dumbest part is you don't need any framework to implement DI. You can just... do it. Without adding huge bloated 3rd party code to your product.
At our company, we're in the process of tearing-out this dumb "StructureMap" IoC/DI library somebody in the past thought would be such a great idea. We're replacing it with... uh. Nothing. 3 lines of new constructor, I guess.
-
@blakeyrat said in How to increase readability of an interface (C#):
The dumbest part is you don't need any framework to implement DI. You can just... do it.
True. Using a framework only makes sense if you'd otherwise have to write shitloads of boilerplate code.
-
@asdf Well, as the developer at our company who recommended it said, if you're writing shitloads of boilerplate code for DI, the problem isn't lack of a framework, but lack of refactoring. Classes don't depend on 10 other classes unless you've already fucked up something.
-
@blakeyrat said in How to increase readability of an interface (C#):
The dumbest part is you don't need any framework to implement DI. You can just... do it. Without adding huge bloated 3rd party code to your product.
It depends on the complexity of graph of objects that your product is using internally. The more pieces there are, the more that 3rd party code starts to look like a reasonable idea. (It particularly starts to look good once the alternative is some home-brewed code that does the same thing, but even shittier. Seen that a few times, and there's no pile of excrement worse than someone's special snowflake homebrew DI/IoC system.)
-
@blakeyrat said in How to increase readability of an interface (C#):
Classes don't depend on 10 other classes unless you've already fucked up something.
In most cases, this is probably true. It's definitely a good indicator that something might be wrong with your design.
-
@asdf said in How to increase readability of an interface (C#):
Next time, can you at least make me cry inside a Monad, where I'm encapsulated properly and no-one else can see me?
You're already in a monad. That's why using monads for modeling is such a good idea. They're everywhere!
-
@fbmac said in How to increase readability of an interface (C#):
I really didn't see many implementations of DI. Maybe because most people know it's bullshit?
Here's one:
class MafiaPlayerController { /** * The constructor * @param {sockmafia.src.dao.MafiaDao} d The dao to use to persist the data * @param {Object} config The parsed configuration file pertaining to this instance of the plugin */ constructor(d) { this.dao = d; this.formatter = undefined; } /** * Activation function for the plugin * @param {Forum} forum The forum object to activate for */ activate(forum) { //Set name myName = forum.username; this.formatter = forum.Format; //Registering commands snipped for length } //[...snip] }
oh, snap! look at that terrible, awful Dependency Injection! What a horrible pattern!
-
@Yamikuronue That is poor man's DI. It must use an interface other you could just use a filthy concrete class.
-
@lucas1 said in How to increase readability of an interface (C#):
It must use an interface
I'd be glad to. How do I make one in Javascript?
-
@Yamikuronue http://www.javascriptbank.com/how-implement-interfaces-in-javascript.html
EDIT: This is a really fucking bad idea to implement this.
-
@Dreikin said in How to increase readability of an interface (C#):
interface IRepo<T> { int Delete(int id); int Delete(T entity); }
What happens if I instantiate
IRepo<int>
?
-
@marczellm Depends on what is inheriting doesn't it?!
-
@marczellm I don't know, but perhaps one could do
x.Delete(id: 2);
-
@marczellm said in How to increase readability of an interface (C#):
@Dreikin said in How to increase readability of an interface (C#):
interface IRepo<T> { int Delete(int id); int Delete(T entity); }
What happens if I instantiate
IRepo<int>
?Then you only have one
int Delete(int)
to worry about, according to VS's autofill.namespace AutoLotDAL.Repos { class IRepoTester : IRepo<int> { public int Add(int entity) { throw new NotImplementedException(); } public Task<int> AddAsync(int entity) { throw new NotImplementedException(); } public int AddRange(IList<int> entities) { throw new NotImplementedException(); } public Task<int> AddRangeAsync(IList<int> entities) { throw new NotImplementedException(); } public int Delete(int id) { throw new NotImplementedException(); } public Task<int> DeleteAsync(int id) { throw new NotImplementedException(); } public List<int> ExecuteQuery(string sql) { throw new NotImplementedException(); } public List<int> ExecuteQuery(string sql, object[] sqlParametersObjects) { throw new NotImplementedException(); } public Task<List<int>> ExecuteQueryAsync(string sql) { throw new NotImplementedException(); } public Task<List<int>> ExecuteQueryAsync(string sql, object[] sqlParametersObjects) { throw new NotImplementedException(); } public List<int> GetAll() { throw new NotImplementedException(); } public Task<List<int>> GetAllAsync() { throw new NotImplementedException(); } public int GetOne(int? id) { throw new NotImplementedException(); } public Task<int> GetOneAsync(int? id) { throw new NotImplementedException(); } public int Save(int entity) { throw new NotImplementedException(); } public Task<int> SaveAsync(int entity) { throw new NotImplementedException(); } } }
-
@fbmac said in How to increase readability of an interface (C#):
@asdf said in How to increase readability of an interface (C#):
The very definition of a pattern is a proven concept
How is any of it proven?
Not that patterns are necessarily based on it, but at least one book can show you how to write proven code. (As in, an algorithm for which a formal proof has been demonstrated.)
-
@dkf said in How to increase readability of an interface (C#):
and there's no pile of excrement worse than someone's special snowflake homebrew DI/IoC system.
Erm. Eh. Heh.
I just decommissioned one of those that I was responsible for creating, a few hours ago. Luckily it was for a tiny side-project that no one knew or cared about, and I eventually saw the @error of my ways and ripped it out. I tend to do all of my experimental ideas in my side-projects, and evaluate how they perform there before I use them professionally.
Hey, it at least had unit tests.
-
@Yamikuronue said in How to increase readability of an interface (C#):
@lucas1 said in How to increase readability of an interface (C#):
It must use an interface
I'd be glad to. How do I make one in Javascript?
Does TypeScript count?
Filed under: It transpiles to JavaScript.
-
@lucas1 said in How to increase readability of an interface (C#):
It must use an interface other you could just use a filthy concrete class.
No. DI just says that objects have their dependencies given to them instead of making them themselves. That works fine with concrete classes if you want to roll that way. It also works fine with the late binding approaches used in languages like Javascript. Using interfaces is just a good way to go about doing the types to support DI in some languages (notably Java and C#) and not a fundamental part of the pattern itself.
-
@dkf said in How to increase readability of an interface (C#):
No. DI just says that objects have their dependencies given to them instead of making them themselves.
Ok, so DI by itself isn't a shitty design. But many implementations of it are. If you use interfaces for things that won't have more than one implementation for the foreseable future you deserve a slap.