-
Notifications
You must be signed in to change notification settings - Fork 205
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
Add private set property modifier #4206
Comments
I've suggested something like that before. Can't find it right now. Strawman syntax: int _value {
get value;
set;
}; This block states that there is a getter named By allowing you to specify an alternative name for a getter or setter, you can end up with default getters and setters for a variable with different names, including one being private. Another way to write the same thing might be int value { set _value; }; because you can't omit a getter, so omitting it is equivalent to (Annotations are not an option. An annotation cannot change language behavior, so |
I like this sintax, for me it works int a { set _a; } What if I set an initial value for 'a'? It would be something like this? int a = 1 { set _a; } |
For each verb in {
Each of those has to be translated into the human language while reading the program (16 combinations in total). |
Introduce a property-level modifier similar to Swift’s
private(set)
functionality. This would allow a class to expose a property for reading externally while restricting write access.Motivation
In Swift, a common pattern is to declare properties as
public private(set)
, which makes them publicly readable but only privately (or internally) writable. However, Dart does not have a similar feature, so we have to create a private variable along with a getter to achieve the same functionality.Swift
Example:Dart
Example:Proposed Solution
_set
@nonVisibleSet
Alternatively, a annotation-based could be another option.
The text was updated successfully, but these errors were encountered: