Idea: Deinterfacing #8510
Replies: 5 comments 12 replies
-
Structural typing would be awesome, but I don't see it ever happening. It's too much of a divergence from the fundamentals of C# |
Beta Was this translation helpful? Give feedback.
-
Sounds like something best accomplished by a source generator: [AutoInterface] // generator keys off of the presence of a custom attribute, or whatever you want
partial class AwesomeService {
public void RunGoDoIt() { }
}
// generator emits the following:
public interface IAwesomeService {
void RunGoDoIt();
}
partial class AwesomeService : IAwesomeService { } |
Beta Was this translation helpful? Give feedback.
-
Tabs would be even less. ;) The language itself doesn't care, you can set the indentation level to whatever you want. |
Beta Was this translation helpful? Give feedback.
-
Ive never seen a codebase where this 1 class - 1 intergace dogma really worked well. People just end up with useless abstractions all over the place, mocks over mocks over mocks and really weak mental model about how their code actually works. Not to mention performance hit this approach brings. Sadly, this is a mainstream enterprise practice. So my question is: maybe just reduce the number of interfaces you dont actually need? |
Beta Was this translation helpful? Give feedback.
-
Hey! Thanks for a lot of comments. Nice! I've checked eShop and out of 44 defined interfaces, only 5 of them have more than one implementations (excluding mocks, tests etc). I can understand the point "we should not write such crappy code", I could event agree with it! Let's do it! But... the reality is that advocated, evangelized way of writing is "write damn interface as you will need in testing". I can check any non-library project on GH or template for "clean code" and those pesky lone-interfaces will be in majority. I think this way of writing will have its place for years - you like it or not! This was advertised for ages by uncles and aunts that we should do it and rooting it out is not an option IMO. About "adding features not bringing to language value". Well, please look at that from different POV.
I would say nothing from the past of lang or dotnet exclude that on first sight. Borrowing term from one of comments, "Overzealous purists of language, should not block small improvements for enterprisey/minority" As of now I see that this could be dropped if someone would revert the river of thought in MS world of MVP to stop "interfacing" - small change as there is not even wide agreement that this should happen. If we cannot change hammered mental model of dotnet dev good code, then can we get painkiller? |
Beta Was this translation helpful? Give feedback.
-
Scenery
As of now, in non trivial code base, average ratio between interface and number of it's implementation oscillates around 1.01 (maybe 1.1 - no measurement, just hunch-based). The reason for that is... testing, mocking, stubbing, etc.
Proposal
Let's have new keyword
interfaceof
that could be used as:interfaceof(T)
will make sure that any type that fulfill public members of T can be used.PS: Maybe we could promote 2 spaces default instead of now (for years) 4 - would reduce number of electrons sends over the wire ;)
Beta Was this translation helpful? Give feedback.
All reactions