-
Notifications
You must be signed in to change notification settings - Fork 230
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
Fix #3119. Don't expose ListValue<T> lists to users #3129
base: develop
Are you sure you want to change the base?
Conversation
Use Collections.Generic.List<T> instead of ListValue<T>. Return a ListValue copy of these lists to user code. Changes: FileContent:binary Lexicon:keys Lexicon:values Part:children Stage:resources Stage:resourceslex String:split Structure:suffixnames Timewarp:ratelist Timewarp:railsratelist Timewarp:physicsratelist Vessel:parts Vessel:dockingports Vessel:decouplers (separators) Vessel:resources allnodes bound variable allwaypoints function Stage:resources, Stage:resourceslex, Vessel:parts, Vessel:dockingports, Vessel:decouplers now return copies instead of references to internal lists. All lists returned by these suffixes don't get modified over time so the only way to tell that they are copies now is to use the equality operator. Stage:resources and Stage:resourceslex returning a reference was a bug.
I'm a little concerned about performance for this one...is there maybe a need for a "readonly list" that these can return, that is easy to construct a copy from if you need it? |
Yes I considered it too. Basically its a tradeoff for consistency over some performance. I want to avoid people having to stumble on these few suffixes that return readonly references and not copies you can do anything with. |
Agree with JonnyOThan. I think this is a documentation fix not a code fix. The docs just need to make clear they are read only (if they don’t already). What is the use case for manipulating these lists that can’t be done with a deep copy when needed? They are used far more often to merely read the current list so not worth the performance hit imho |
It seams to me the better solution from a performance stand point (assuming we want these lists to be modifiable in the first place) would be to preform the cast to a generic list when someone preforms a modification on one of the read only lists as apposed to on the initial list construction, which should only modify the suffixes: It is also a rare operation that some one wants to modify these lists as I only ever encountered the one person asking after the problem which is what prompted me to make the issue in the first place. And it is a far more common operation for someone to do as part of main loops
or
so avoiding performance impact on these would be good. |
Yeah copy-on-write is another method, but more complex to implement and maintain. No objections though if someone wants to try it. |
…rts, dockingports, decouplers suffixes to return readonly references to internal lists
So is the |
It would be perfect to:
But I don't think there is an easy way to achieve all three. Keeping typesafety seems less important |
Basically in the first commit I was prioritizing the first and the third point, now I prioritize the first and the second point. If there was some middle ground I missed let me know |
Why is it good to not expose |
OK I read through #3119 and I think I understand...the type returned by those suffixes have a hidden restriction beyond what one would expect from the KOS I think I buy that argument, and I'm not too worried about a performance cost for changing |
I did revert some changes from the first commit and now these ship suffixes don't create a copy. Is there anything else that needs to be addressed? |
Ah yes I see that VesselTarget.Parts isn't a copy, cool. But maybe I'm still confused...if the return value is not a copy then users shouldn't be adding things to it anyway, right? So there's not a problem if it's a specialized list type. If it IS a copy then it should be I'm also open to the possibility that suffixes that don't return copies should return something that isn't a list at all, but maybe that's a different conversation. |
Si
El sáb, 1 de feb. de 2025 11:42 a. m., JonnyOThan ***@***.***>
escribió:
… Maybe I'm still confused...if the return value is not a copy then users
shouldn't be adding things to it anyway, right? So there's not a problem if
it's a specialized list type. If it IS a copy then it should be ListValue
because the user could add things to it of any type. Do I have that right?
So should vessel:parts still return ListValue<Part> ? And then we don't
need to lose the typesafety on the C# side.
—
Reply to this email directly, view it on GitHub
<#3129 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/BLE7DNQPJKMZKZ7U5YFIZMT2NUBQZAVCNFSM6AAAAABWE5WO3GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMRZGA2DENRUHA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Yeah you have that right. There are 3 main problems with leaving |
Thanks for explaining that. I think losing typesafety is the least bad outcome here. I think maybe we need a refactoring where |
Use
Collections.Generic.List<T>
instead ofListValue<T>
. Return aListValue
copy of these lists to user code.Changes:
FileContent:binary
Lexicon:keys
Lexicon:values
Part:children
Stage:resources
Stage:resourceslex
String:split
Structure:suffixnames
Timewarp:ratelist
Timewarp:railsratelist
Timewarp:physicsratelist
Vessel:parts
Vessel:dockingports
Vessel:decouplers (separators)
Vessel:resources
allnodes bound variable
allwaypoints function
Stage:resources, Stage:resourceslex, Vessel:parts, Vessel:dockingports, Vessel:decouplers now return copies instead of references to internal lists. All lists returned by these suffixes don't get modified over time so the only way to tell that they are copies now is to use the equality operator. Stage:resources and Stage:resourceslex returning a reference was a bug.