You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like it as a simple way of making things "read-only".
I often use getters for things that could be done in a function, but where it makes more sense to return the result as a variable, for example, a function like last_tile(), I almost always implement as a property instead: tiles.last_tile
When I wrote a lot of c#, I loved being able to create a getter simply by using =>.
The downsides I can think of is that it could somewhat confusing to see the difference between Type hint -> and Getter =>, but since Getter => won't be followed by a Type, and -> always is, I honestly doubt that would be an issue.
:=> might be a bit less intuitive, so might raise more questions, but it seems like a very google-able question.
If the missing colon after the statically typed properties Type causes issues with implementation, then maybe something like
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The why
I use
get
a lot.I like it as a simple way of making things "read-only".
I often use getters for things that could be done in a function, but where it makes more sense to return the result as a variable, for example, a function like
last_tile()
, I almost always implement as a property instead:tiles.last_tile
When I wrote a lot of
c#
, I loved being able to create a getter simply by using=>
.e.g.
I think it would be reasonable to add this feat to GDScript too.
Example syntax
For statically typed properties
An example of the proposed syntax:
In my opinion, that feels much nicer than:
Or, using the alternative syntax
Inferred type properties
For inferred typed properties, we could lean into the already existing syntax
:=
, and use:=>
:This again, in my opinion, would feel nicer than
Reservations
The downsides I can think of is that it could somewhat confusing to see the difference between Type hint
->
and Getter=>
, but since Getter=>
won't be followed by a Type, and->
always is, I honestly doubt that would be an issue.:=>
might be a bit less intuitive, so might raise more questions, but it seems like a very google-able question.If the missing colon after the statically typed properties Type causes issues with implementation, then maybe something like
could suffice.
Let me know your thoughts
What do you think? Please share your thoughts 🐦
Beta Was this translation helpful? Give feedback.
All reactions