-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Implement Set inside Variant #94399
base: master
Are you sure you want to change the base?
Implement Set inside Variant #94399
Conversation
Note that the opposite of "disjoint" is "non-disjoint" or better "overlapping", if we're going to use set theory terms I think we should use established ones ("joint" is not one), but I'd say the more accessible and generally useful phrasing would be "non-overlapping" and "overlapping" for what are now called "disjoint" and "joint" |
Using placeholder icon for now. |
|
That's because the doc isn't generated so it cannot be looked up, the docfile has to be generated first |
102906d
to
08882f8
Compare
Woops |
8f763c8
to
6714305
Compare
Since the file output matches the unit tests expected, i won't let it stop me. |
I personally would like set even though it bloats variant by another type. Not sure how much of a review I can do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial feedback
28cf3fd
to
e44a479
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I'm not convinced of the GDScript syntax {A, B, C}
. It adds unnecessary complexity when parsing. Also I don't think it is very readable. I would prefer to constructs sets like packed arrays:
Set()
.
@@ -2975,6 +2975,13 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_dictionary(ExpressionNode | |||
case GDScriptTokenizer::Token::EQUAL: | |||
dictionary->style = DictionaryNode::LUA_TABLE; | |||
break; | |||
case GDScriptTokenizer::Token::COMMA: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that parse_dictionary
should call to parse_set
. Better use another method parse_dictioanry_or_set
that delegates to both of the methods.
It would be a lot straight forward to use the mathematical and python syntax as its easier to understand/comprehend and even use. |
I'd say the |
Could you elaborate why you think it would be better to understand/comprehend? Not everyone might be familiar with mathematical notations. And while not everyone might be familiar with the term "Set" as well, it at least gives a good search query to start (and a target for symbol lookup to get to the documentation). Also while the notation is well established in math, I don't think it is in programming, or is it? I personally wouldn't feel certain that I'm looking at a set if I see it in a language that I didn't know. It might be a tradeoff for the usage if you have to write it out all the time. But given it's only three letters I don't think it's that important. If it turns out to be a real problem we could implement vararg methods for common set operations, but given that there is no overloading this might get confusing. |
I myself brought up concerns about the name "Set" itself. I'm fully aware this is how it is most commonly known as, but I wonder if it's worth evaluating another name for this type. Main reason is because "set" is used in Godot exclusively to refer to... a setter, setting a property. |
I mean I can kind of understand that sentiment, but I can't really think of any another name that wouldn't lead to the same effect in the other direction (avoiding calling our I mean if there is a concrete idea for an alternative name we can evaluate it, but I can't think of one. |
Agree with Mickeon, it's particularly bad because Godot uses a ton of "set" identifiers all over the place, including
But |
Some thoughts regarding this feature in general:
|
I think this should be a The main reasons to consider this as a
But 1 has been questioned, and I agree that it both isn't very necessary to have it, and that it would be hard to do so in a way that doesn't both create confusion and make parsing more complicated For 2 there's no implementation for it, and doesn't seem to be any intention to add it I also don't necessarily see the need for 3, I'd consider sets here a matter of processing and not data storage, and with a good set of methods you can easily just input an So for me only 4 stands out as a real benefit here, but I don't think a high performance and tight coupling is a critical part of this, it would potentially be if this was a highly needed feature, but I don't think that there will be a large number of users using this in performance critical areas tl;dr; |
Should we maybe move over to the proposal for further discussions like this? |
I'd say most of this is implementation related which belongs here, though the broader discussion of |
I mean, the whole point is all of the set operations. In terms of type conversion and coercion. It should be able to swap too and from an array. On the syntax points here, Python has made use of the {} set syntax since forever, and I mean, godot has borrowed a tonne of its syntax from python anyway. It seems to me that the argument isn't so much against the inclusion of sets, and more for that fact the type system needs fixing. Its clear that it hasn't been written with the future in mind, and is rigidly designed in such a way that it doesn't support reasonable additions. |
Serializing will not work if Set is RefCounted, if you try to serialize with
This is the reason why i wanted to add it using that syntax. |
We could add corresponding methods to [2, 2, 3].merge_with([2, 5]) # [2, 2, 3, 5]
[2, 2, 3].merge_with([2, 2, 5]) # [2, 2, 3, 5]
[2, 2, 3, 5].intersect_with([2]) # [2]
[2, 2, 3, 5].intersect_with([2, 2]) # [2, 2]
We could solve this on the serialization side by adding special handling for the godot/core/variant/variant_parser.cpp Line 1087 in f6c7b00
|
That's a good point. I didn't think about that. (Edit: see dalexeev's comment ☝️)
I don't think that really matters. GDScript has the same syntax in a lot of places, but it also borrows from other languages like javascript or lua. In the end we need to evaluate new syntax with GDScript in mind and not python.
Not sure about that. Rust for example can do all its coercion at compile time, that's why it's basically free for cases were it isn't needed. GDScript being gradual typed can't rely on that. So all code or at least all unsafe code would get slower through this even when not using sets. |
For array we could also add a method like the STL Edit (to not clutter): The only necessity of adding a method to add a whole bunch of entries at once would be to allow using reserving etc. (it'd be different if we used a tree based structure, there storing and reloading would be something that could be made significantly more performant) |
I guess we don't have a mechanic for modules or gdextensions to add such handlers right? |
We use a switch case, it doesn't get slower. |
I've decided to go forward with implementing typed sets as well, as we cannot make |
Hi there @RadiantUwU ! I added the While some of us can offer you reviews and such, it doesn't necessarily mean that this PR would be merged even if everything is alright and up to standards. You put a lot of work on this PR and we are grateful for it. We'll take time to review it and decide whether or not it is right to merge. We just want you to know the odds of the outcome in advance. |
closes godotengine/godot-proposals#867
TODO:
TODO AFTER MERGE: