Repository navigation
Redesigned range type - #3168
YohDeadfall wants to merge 2 commits into
Conversation
a600c52 to
08468c0
Compare
1533c4e to
92d7828
Compare
|
I promise I've reviewed this while trying to keep an open mind, and I think there are some good things here. I still largely think what I wrote in npgsql/efcore.pg#785 (comment) - we've received one user complaint over the years, where the user acknowledged this is API nitpicking. I agree the current API isn't ideal, but I don't think it's real problem that we need to spend time on, which we could use for real, valuable features. I'm also not a fan of introducing big breaking changes just to make the API slightly better.
Another (breaking) proposalIf I were designing the new API today (and breaking everyone), I'd go down the route of using null to represent infinity as previously discussed:
There are probably some complications with this - especially with how the type handler would be implemented. But from a user perspective this seems like a nice API, and you don't have to have to deal with the additional bounds types. @vonzshik @Brar it would be good to have your thoughts on all of this. |
|
I like the idea with nullable types, but the idea was to represent PostgreSQL range types as closer to backend types as possible. Therefore, I have to make the bound type since there are two types of them: inclusive and exclusive. Nullable types lack of it, but with them API is more friendlier except that there still will be four constructor parameters with which am not happy. I specially not implemented parsing exactly for the same reason you mentioned. Besides, don't forget that the element types also must be parseable which won't work for new date time types. |
Never use static constructors for that cases. It runs only once even if it throws. Such cases must be handled by members. |
I don't see how the representation with NpgsqlRangeBound is closer to the backend types than the proposed one with nullability... PG has no "range_bound" type or similar. It's true that we'd still have to allow people to work with inclusiveness, but I don't see the problem with a four-parameter constructor. And again, with your proposal, people have to now do
I guess I don't think that Parse is very important - the main point is to not introduce breaking changes without a good reason (and this will continue to work for e.g. int). If we end up redoing the whole API and introducing big breaking changes anyway, I won't be against removing Parse. If we don't do such changes (or do changes which aren't breaking), then I don't see a reason to remove it.
So, what exactly is the problem :) Yes, it's good for it to run only once (this way they don't need to run every time in the members), and it's good for it to throw, no? |
|
BTW just in case it wasn't clear... At the moment I don't think we should do my nullability-based proposal - I don't think we should do anything (except possibly to change the accessors to throw when the bound is infinite). |
That's what I don't like in my proposal. Okay, will use nullable types and four parameters in constructor, at least it's better what we have no.
I mean that if an exception happens in |
Why so? There will be other breaking changes, so it's a good time to push them all and not one by one. |
Just because I think we should only break stuff if there's a good reason to, and here it's just some API nitpicking which only one user has complained about... This would have an impact on everyone using ranges, and for what... |
|
Do I correctly understand that you're not interested in taking a new design at all and that it won't happen? |
|
Am I missing something, or we're rewriting the range API so:
|
|
@vonzshik, you're right, but mostly I was interested in the first point and other usability improvements. And the proposed implementation stores data exactly as PostgreSQL does, so write and read operations only serialize elements. It was done as a part of new type handling, but spun it of for simplicity. |
My personal opinion is that there's not enough reason to completely break people by inventing a new API - the problems aren't serious enough and almost nobody cares. I think it's more reasonable to improve it without breaking, if that makes sense. But I know we have differing opinions here. If the others (@vonzshik, @Brar) think that we should spend time on this and introduce a new, breaking API, then I will be OK with it. I think at that point we can also discuss which exact new API shape we want to have (i.e. with a new bounds type like in your proposal, or nullability-based). Does that sound good? |
|
Of others will be involved too, am fine with it. Just to point out, not a single dev complained about the API, there were other participants. Me too thinks that it's one of ugliest things I saw (sorry, but it's really so and it was hard to use during times when I was an user too). |
For a single constructor with 6 parameters - that sounds like a bit of an exaggeration :) But let's see if the others thinks this is worth our time and the breaking changes being proposed. |
|
My intention here to make it usable and construct in a fluent way without taking so much parameters and so. Even before contributing here I wasn't able to understand how it was possible to write such a thing, why not |
|
As I said above, if you think we should expose the enum publicly and accept that in a new constructor, that may be possible and it wouldn't be a breaking change. Many problems can be solved without causing trouble for existing users. Speaking of API usability, I'd personally be quite turned off by a range API that forces me to do |
|
Agreed on the last sentence, there's an additional member to be accessed. It was done according to C# guidelines saying that |
|
@khellang, your opinion is welcome here! |
|
It's good that I had no time yesterday on the issue and that I spent a lot of time on Rust for two reasons:
So... Despite my first impression on two generic parameters, am not sure it suits well in .NET as well as other languages. Yeah, the idea deals with the excessive member access, but at the same time it makes type handling trickier, the resulting type depends on data which is the same bad idea we had recently consider numerics. It also doesn't follow discriminant unions and the idea of decomposition and single responsibility. In the proposal I made, a bound is a thing which combines all data about it into a single object and behaves exactly as the nullable type. Unfortunately, .NET means runtime compilation, so there's no way to decide what kind the cast operator should have, Therefore, I don't think that I even will try your idea. While it looks better at first, afterward there's a lot of issues to deal with. |
That could be the case - though type handling generally shouldn't limit the APIs we present to users - it's there to serve us, not the other way around. I wouldn't assume it's problematic without trying, in any case.
I don't think the resulting type depends on data. If users use the generic GetFieldValue, they are telling us which type they want to read (like in all other cases). If the use the non-generic GetValue, we just always return an NpgsqlRange with infinitable bounds (e.g. NpgsqlRange<int?>), since that can accommodate any data. I wrote that above in the proposal.
I don't really understand what this means :) But again, I prefer that we first make the decision if we really want to break everyone over this, before we discuss the merits of each breaking proposal. Let's wait for more opinions. |
It's while
I mean we can't follow PostgreSQL ranges as they are due to language limitations and other reasons, so there's a need of specifying a kind of a bound. Instead of doing it directly on a range, the logic moved to a separate type which is Therefore, I conclude that am satisfied with mine proposal since it shares the same ideas as other types in .NET as well in other languages/platforms. It's clean enough even if it adds one more accessor to get a value.
Am not forcing you to approve it, while it would be a pleasure to see you being not so conservative and more willing to improve even such a thing. I care a lot about usability, good design even if it looks minor, you know. Maybe I should be less careless in case of compatibility... Anyway, it was just to summarize my morning thoughts on it and share them with reviewers. |
|
My not-so structured thoughts on this pr: The proposed API does look correct. That is, left and right boundaries are separate entities, which we can view, use and mix. I do like this idea. One of the points of any major release is we're allowed to introduce breaking changes. And I have nothing against them in the API, that is if they are limiting us in some way. But that's not what I see here - we're rewriting the API so it would look nice (I mean, it should be very simple to add a custom API, which would hide all this ugliness, so you never have to deal with it). That's cool and all, but not something I'm thrilled as a user. All in all, I'm for the way, when on the next major release we deprecate the previous API and it's removed with the next one. |
It's possible only in COM world where you just add a suffix to an interface/type. There you can't do so without having another type or a new place to put it in. |
|
@YohDeadfall I think @vonzshik means having both APIs in parallel in the next version, with the current one obsoleted, and then remove the obsoleted one in the release afterwards. |
|
I understand, but can't see how it's possible at all. In COM all interfaced are resolved by IIDs, but in .NET by names and it's not possible to have two types with the same name. |
|
It would mean two different type names... |
|
Or namespaces. But from what I've seen, there should be a simpler way. I'll try to take a look in the next few days. |
|
@YohDeadfall I'm going over old PRs to close some of them out. I don't think we ever got to anything concrete here right? |
|
Yep, correct. I have nor time neither intentions to continue on my previous work. |
This change was split from a large improvement of type handlers am working on to simplify review process. The idea of the new design to minimize API surface and make it more fluent and modern. The bound type represents a discrimination union which could have only three possible values: infinite, inclusive and exclusive. While it exists it isn't used inside the range to store values, but the range can return bounds as separate parts.
Fixes #2314