-
Notifications
You must be signed in to change notification settings - Fork 899
Type-safer Diff.Compare at compile time #1176
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
Comments
@Therzok 🆒 idea. However, I'm not sure I fully understand why we should make How about just creating a marker interface, make
You lost me there, mate 😉 |
Well, the user could take the native diff format and transform it how they want.
Without something like that, an empty IDiffResult could be used by the user without any problem and they could just shoot themselves in the foot, and we wouldn't have any way to programatically get rid of the mapping dictionary and the runtime type check. That's why the DiffSafeHandle proxy which could be used by LibGit2Sharp or a consumer to create their own DiffResult type. |
Idea in the clear:
|
And we would end up with
|
I'm not sure I get why you're so worried about a user adding And even if a user did try to somehow make use of |
So, let me write up what I thought about. The initial IDiffResult constraint is insufficient.
Would be methodless, we wouldn't have any way to have a common denominator that says we can transform a
Using this way, we get rid of this and this ugly implementations. But we can't construct the
LibGit2Sharp will continue having its own implementations, but the users can do their own things (if DiffSafeHandleProxy is not opaque). The initial scope of this is to get rid of the runtime checks. The bonus scope is that we can possibly allow user-defined |
The dictionary of types is certainly a hack, and getting rid of it in favour of letting the compiler do its job is certainly Good. But exposing the handle to a consumer of the library... if you want your own data type, I'd much rather you inherit from one of the existing types. The need for an instance method instead of a constructor which knows how to read the native data is a bit annoying, but it looks like this is the way it'll have to be. Can we keep the interface internal to the library? Can the compiler perform its type checks with the interface even if a consumer of the library cannot see it? |
It's public facing API by becoming a constraint.
The consumer will have to know about the |
I suppose it makes sense you can't describe a generic method with secret constraints. The wrapper types are a bit annoying, but on the whole better than the type dictionary (what is this, ruby?), and looking into it, I can't find a better way to describe the constraints than what you describe. 👍 from me, FWIW. |
@Therzok Let's try this. Do you feel like sending a PR? |
Sure. |
This is taking a turn for the worst. The I'll push what I have for now, but it's not something I'm glad with. |
This allows for a typesafe Diff.Compare model. This commit introduces a new IDiffResult interface which marks classes which can be passed to Diff.Compare<T> so we get rid of the runtime exception. Fixes #1176.
Currently, we're allowing Compare with T being any kind of class.
Should we introduce an
IDiffResult
interface with from which the classes we support as convertible fromDiffSafeHandle
? ThenDiff.Compare<T>
would beT : IDiffResult
.This would improve a few aspects:
I know this would bring an implication that
DiffSafeHandle
would become public, or we can expose a proxy class with methods which interface the native methods.The text was updated successfully, but these errors were encountered: