[Proposal] Local functions for properties that are shared between the getter and setter #8755
Replies: 4 comments
-
This seems to be in the same vein as #133. If property-scoped fields are considered I don't see why they also couldn't include property-scoped functions. |
Beta Was this translation helpful? Give feedback.
-
And then property scoped nested types! |
Beta Was this translation helpful? Give feedback.
-
If we have property scoped fields and property scoped methods... what about property scoped properties? 😄 |
Beta Was this translation helpful? Give feedback.
-
@Neme12 Yo dawg, I heard you like properties ... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, we can have local functions for a getter or a setter, like so:
However, I don't find the need for this that common. What I do think is more useful is being able to define a function that is scoped to the property such that both the getter and setter can use it, as sometimes they need the same tools to work with.
Example:
This isn't easy to read and requires writing the same thing twice. The current way to do this would be to extract the method, but then it's visible to the whole class, which isn't neccessary, seeing as it's only used inside the property.
Proposed Solution:
To me, this is much cleaner. They both can use
CoordInRange
, the code is much easier to read, and I'm not repeating any code, nor am I exposing the function that's only used once to the entire class.Beta Was this translation helpful? Give feedback.
All reactions