-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Immutable variables #23695
Comments
Though personally, I prefer |
@somnivore |
C# has it as |
what about using |
@blain1972 Most languages that have a declaration of 'ref' use 'ref' as the mutable declaration where the default is immutable. Using it opposite in Godot sounds rife for confusion. Most commonly |
I am in favor of a |
I'm in favor of @YeldhamDev |
C# has a keyword called
|
Why don't you like |
I'm in favor of Edit: Swift also uses the |
I also support |
Coming to GDScript after doing a coding session in Dart, which has a similar concept of |
I programmed in Scala for quite some time and there are zero practical issues with Honestly, I find |
The value is immutable. Godot has non-pointer (I don't like calling them references because it means something different in C++) types like int and float, where their values aren't pointers. It's just that for "array values" or "dict values" the value is a pointer, not the array or dict itself. |
What's the difference between I speak from a position of very little programming experience, so sorry if this seems like a stupid question! |
@WARIO-MDMA |
@YeldhamDev I see. Thank you for clearing that up. |
@YeldhamDev This may not necessarily be the case. We could still require |
An immutable variable declared via let would have to be initialized immediately and then would never change within that scope. The difference from const is that it can be created within a scope at runtime. It's not constant (ie always the same value) - just immutable (ie it's not able to be reassigned after declaration). |
How would that work with the usage example I gave on the first post, about using it with |
It wouldn't work. Maybe modifying I don't think it's too much of a problem UX-wise to allow later definition for other Maybe you could use static checks for When GDScript becomes more performant it may also be a performance concern that you have to dynamically perform a null check, but at the moment it is not an issue because of the high overhead interpreting bytecode. Just make sure the dynamic check and the assignment are part of the same bytecode instruction so that you don't double that overhead. |
Closing in favor of godotengine/godot-proposals#820, as feature proposals are now tracked in the Godot proposals repository. |
A middle term between a normal
var
, and aconst
, that once set, would remain forever with the given value. A good syntax could be using a word short as "var", like "let":One of the main uses of immutable variables would be pairing it together with
onready
, when creating variables to keep stuff like nodes and certain references:onready let var_name = $Node/SubNode
The text was updated successfully, but these errors were encountered: