Skip to content
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

Class private fields and methods #4253

Closed
DartBot opened this issue Jul 30, 2012 · 6 comments
Closed

Class private fields and methods #4253

DartBot opened this issue Jul 30, 2012 · 6 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jul 30, 2012

This issue was originally filed by domi...@google.com


Support class private fields and methods.

Proposal for syntax: Double-underscore prefix. Eg:

class Point {
  num __x, __y, __z;
  Point(this.__x, this.__y, this.__z);
  ...
}

When writing larger scale apps, it is important to be able to define class APIs for public use (often just one or two methods), and the APIs that should be available for library implementation (the majority of the API), and the private implementation details of a class. The distinction between the last two is not currently present but will aid developers who read code in understanding the original intent.

@anders-sandholm
Copy link
Contributor

Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Nov 6, 2012

I doubt if we'll tamper with Dart's privacy rules, especially in this particular way. In a dynamically typed language, class privacy is difficult to enforce efficiently. You could have object level privacy though.


Set owner to @gbracha.
Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented Nov 6, 2012

Added this to the Later milestone.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@munificent
Copy link
Member

We've discussed this off and on for a long time. Our feeling is that it is hard to implement efficiently when you are dealing with dynamism and doesn't add much value. Libraries are the level of encapsulation in Dart. A class in one library shouldn't need to hide stuff from another class in the same library. If it does, you can always move them to separate libraries.

Yes, this takes some getting used to when coming from a more class-based language like Java or C#, but I think the result actually works out really well. There are some other variations on privacy the language team has talked about (protected, object-privacy, et al.), but we're happy with not supporting class privacy right now.

@munificent munificent added the closed-not-planned Closed as we don't intend to take action on the reported issue label Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants