Enhance Visibility Control with @private and @public Annotations in Dart #4189
Labels
feature
Proposed language feature that solves one or more problems
state-duplicate
This issue or pull request already exists
It would be nice if we could annotate a normal property with a
@private
or@public
annotation to declare its visibility.This way, we wouldn't have to struggle with the, in my opinion, impractical underscore convention for visibility. While it’s a clever approach, it’s not very practical.
Example: Current Dart Visibility Convention
In Dart, you use an underscore
_
to mark a property as private within the library:However, this convention relies on naming rather than explicit annotations, which can be error-prone or less readable.
Proposal: Use Annotations for Visibility
Imagine if Dart allowed visibility annotations, making code more explicit and standardized:
With annotations, changing visibility would be cleaner and would not require renaming properties. For instance, switching
privateProperty
to public would be as simple as changing the annotation:This approach could make visibility declarations more robust and readable, reducing potential naming conflicts and confusion. It would also integrate better with modern language features like metadata or decorators.
If Dart supported
@private
and@public
annotations for visibility, a couple of issues with the current implementation would completely disappear.The text was updated successfully, but these errors were encountered: