-
Notifications
You must be signed in to change notification settings - Fork 899
Remove extension methods #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove extension methods #1093
Conversation
Why Extension methods? As a LibGit2Sharp developer, I find it really hard to find these overloads when they're off hiding if Just my $0.02. |
Well, most of the overloads already live in However, I agree that none of those arguments are pure, undeniable and objective ones. As such, maybe would it be the proper time to make a final decision (BTW, I thank you @ethomson for having raised this before I'm done coding this PR 😉) Who's in favor of /cc @bording @carlosmn @dahlbyk @jamill @jeffhostetler @shiftkey @whoisj |
feels ignored I'm in favor of Extension methods. I've never been a fan of all overloads functions in one place, especially when they're convenience functions provided to transform some parameters into others, or use default values in place of parameters aka just wrappers. |
Generally I'm either for or agnostic of extension methods in C# due the way the compiler and runtime work to make it "just work". However, I do not believe we should be moving virtual methods from an inheritable class into extension methods. Doing so effectively takes control away from the inheritor. While the inheritor could have I am a little concerned about calling partial class implementations So while this is cleaner, I sadly feel I need to 👎 the change as is. 😞 |
Why extensions, then, and not partial classes? |
If it is about separating the implementation into multiple files so we have the core plus convenience, functions, I agree that partial classes sound like a much better match. Extension methods are made so you can inject methods into external code, but we own all of libgit2sharp; partial classes would allow for the code to be split across files but still clearly signal that it's our code. |
Thing is, why would you have different behaviours between
That's even better, imo, I'm up for this. |
@carlosmn in many C# projects, extension methods are also used to implement methods which cannot be overridden as well. Not that I agree with that, but it does enable the creation of partially sealed classes. That said, I don't think that this is the point of this PR and I full agree that |
Why not? What if a service does OI logging and they wanted to hook one of the methods and add a logging event in it? What if an implementation wanted to prevent the use of commitish and wanted to replaced one of the methods with a We cannot pretend to know how the library will be used. We can only provide the most useful library possible. |
So partial classes would be a 👍? |
I do believe that is the consensus. 😄 |
I don't see much point in breaking out partial classes, TBH. |
@dahlbyk Meaning everything in one file, or you prefer the status quo using extensions? |
I haven't struggled with the extensions, personally, so I lean toward:
I'm not sure how much I buy the "what if we need to inherit?" argument because we return concrete implementations throughout the code. Outside of testing I'm not sure how it would ever be useful to override our virtual members. |
I always come back to the canonical use case for partial classes - codegen. Beyond that I'm generally skeptical about it's value - perhaps there's some underlying issue which is being masked by extracting partial classes? Maintainability? Complexity? Extension methods are okay, but again, my favourite use case for them is "for types you don't own". Beyond that, I'd push back and question what problem we're trying to solve here. |
Indeed, fastest consensus reach ever. 😜 |
As it looks like I'm the only one who dislikes overloads living next to the concrete implementation, how about just getting rid of the xxxExtensions.cs files and moving everything from them back in xxx.cs files? |
I would be fine with folding xxxExtensions into the "parent" class with the possible exception of classes that implement interfaces. Then again, our interfaces really aren't meant to be implemented externally, so it may not matter if it would be tedious to reimplement them. |
@dahlbyk Good point regarding the interfaces.
Do anyone oppose to this? |
I've started to work along @dahlbyk's proposal. How does it look? I've also taken the opportunity to surreptitiously introduce some breaking changes. |
Seems reasonable to me. I do prefer concrete implementations to extensions. 👍 |
Are these adjustments worth a breaking change? Or do we not really care until stabilization is complete (I'm out of the loop on those discussions)? |
I'd like to keep them as I have plans to use, at least some of, them. |
Add tests for them, exclude |
I'm not sure I'd be able to add interesting tests (other than copying the implementation). How about I mark, for now, the enum as |
That should be fine. It'll be a few weeks before I start on my submodule stuff - no point in using your time now for something I'll need only then. 😊 |
Done. Ready for final review.
@whoisj 😍 |
If someone actually uses this API they will be broken when we remove it. While we are pretty good about testing APIs, surely this isn't the only one missing test coverage, so I don't know if missing test coverage is reason enough to remove it. |
Beside we can't publish anything until #1091 is fixed. |
@dahlbyk 💎 |
Pushed a rebound, feel free to discard. I don't see a reason to drop these methods for lack of test coverage in a PR about removing invalid extension methods. If extensions on an enum are considered valid (and they should be, IMO), then we might as well test accordingly. |
I won't. Your approach is far better. Thanks for this! |
bdfa49d
to
025b273
Compare
Preliminary step to #1076