Replies: 1 comment
-
|
I think these are good ideas. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Looking at several issues involving mutable fields of structs and interfaces, and seeing people wanting to interact with those fields as if immutable, it appears that the situation could be solved by expanding the
clone()concept or doing something similar. A possible way to avoid or be an optional alternative to various cases of reference, dereference, and const usage.Allow making immutable copies of structs or interfaces with mutable fields.
The user can assign the immutable copy of the struct or interface to an immutable variable or const.
Allow "freezing" of struct or interface data inside of a function, without worrying about changes.
Allow "freezing" of struct or interface data when assigning to const.
When
clone()is not used on structs or interfaces with mutable fields and that exist outside of a function, it can be assumed that values of their mutable fields can change.If attempting to assign a struct or interface with mutable fields to an immutable variable or const, perhaps a notice can be given as a reminder, that
clone()could be used instead.Put the onus on and empowers the programmer to manage their expected outcomes.
Beta Was this translation helpful? Give feedback.
All reactions