_This issue was originally filed by potoms....@gmail.com_
The Dart team decided to use underscores to hide variables in libraries. While this seems to be a common practice, a lot of people don't like to mix their variable names with semantics.
That's why I propose to add a type modifier like 'private' or 'hide'. I think both practices can be incorporated in the language and everybody would be happy.
One developer could write:
private int myVar = 10;
myVar = myVar + 1;
while another developer prefers:
int _myVar = 10;
_myVar = _myVar + 1;
Personally I'm in favour for the modifier approach. And I think underscores are a bad idea. It is clear a lot of people like the underscore approach (including the Dart devs) and I respect that. But I think there's a place for both styles in the language.
_This comment was originally written by [email protected]_
_Removed Type-Defect label._
_Added Type-Enhancement, Area-Language, Triaged labels._
I have sympathy for using modifiers and keeping naming and privacy orthogonal. However, I don't think we'd support two totally different ways of doing the exact same thing. Features aren't free - they have costs in many ways: implementation, tooling, training etc.
_Set owner to @gbracha._
_Added WontFix label._
_This comment was originally written by rfab...@planalytics.com_
This issue is a gentle way of trying to survive using a language that is otherwise pretty nice. This issue of private/public is THE BIG issue that will make Dart not as dominant as it could be. As a Java Developer (and 20 years experience), I know this will be the #颅1 issue that will drive people away from this otherwise very nice language.
Correct way:
Everything private by default with class based privacy.
Use @颅 for properties and public things in a suffix style like unix symlinks.
(Raw values is a much less important use of the important character "@")
PS: (another issue, sorry): Use more lowercase. "foreach" instead of "forEach".
PS2: favor composition more than subclassing. "Allan Holub", Fragile Base class.
PS3: Don't focus so much on Javascript and Java style to exclude other goodies.
(add Perl regex, Ruby constructor syntax, "initialize", C/Perl terseness "fopen")
Take a 10 day open vote showing the two alternatives and some nice examples.
See what the common "people" like.
My 2 cents.
jwait.com
_This comment was originally written by potoms....@gmail.com_
I agree,
This will be the number one 'feature' that will drive more people away from Dart than attract.
I like the library based privacy. Fields should be exported out of the library with the 'export' keyword (or alike).
There were big discussions about the underscore and some people seemed to be very religious about it. I wanted to please everyone by proposing this issue. But like Gilad said it is not a good idea to have two different ways of doing the exact same thing.
I suggest you open a new issue with your ideas so it can be discussed. This issue is closed.
_This comment was originally written by IanDavid...@gmail.com_
I too would like proper class based privacy, IN ADDITION to the package privacy, which is great too.
My number one issue is proper encapsulation. Within the SAME package I want to write interdependent classes but even then these classes only interact via the public methods/properties. Class A should only be able to use Class B's public methods. I want my implementation to be hidden.
Coming from a Java and C++ background I would prefer private and public keywords, or just private to keep it simple. Keywords are simpler to search on than _.
An alternative if you want to keep symbols would be UML:-
private = '-'
public = '+'
protected = '#' (I don't like protected so don't care about it)
In essence, to me, there are MULTIPLE LEVELS of encapsulation I care about, class and package. If the recommendations for package granularity are that a package should contain all simultaneously versioned things, as opposed to package per class, then we need another mechanism.
JS access modifiers don't exist. People use _ to indicate private stuff. Dart can do better.
Thanks!
_This comment was originally written by atr...@gmail.com_
I'm currently comparing Dart and HAXE as alternatives to CoffeeScript and I have to say, the lack of visibility modifiers is definitely a glaring omission for me.
(the other - potentially related - being lack of namespacing)
Visually I find the underscore syntax unappealing and not helpful when it comes to "programmer joy", working with variable names. It adds a lot of visual clutter to my source files and is not evident to newcomers or even myself most of the time. I'm constantly having to remind myself that what I'm reading is a private variable. True enough, the syntax also seems to just outright discourage people from modifying visibility at all.
We need at the very least protected and public. HAXE does this and simply ascribes protected behaviours to the private modifier.
Beyond this, I think visibility should not be resolved "package level". While it doesn't make sense to me now, I admit it's only because I have yet to see a cogent explanation as to why it's a better approach.
_This comment was originally written by rfab...@planalytics.com_
I've lost interest in Dart mainly due to this issue being ignored.
Alas, too much Javascript style and not enough Java style in the design.
Ideally... there would be "public/private" keywords with one of them being default.
(Of course I'd prefer private default more like Java over Javascript)
And, ideally, Dart could improve on Java by simplifying and removing the "protected" idea. I've programmed years without ever really needing "protected", but I rely on public/private all the time. (Agree with #颅5 comment). Basically, Java is right and Javascript is wrong when it comes to public/private class privacy rules. Why follow Javascript?
I'm only saying this in case there is some future derivative of Dart that wants
to do things in a different way.
A few other improvements would help also:
1. Constructors like Ruby's "initialize" instead of redundant class name way.
2. More help for someone starting out with Dart and wanting to do server side coding to learn Dart, and wanting to replace Ruby-Perlisms like "system" but getting way too much async complexity presented. Often I just want synchronous done simple.
Totally agree with #颅6 about the underscore being "unapplealing".
Most serious programmers have more experience with C,C++,Perl,Java background than Javascript. The underscore choice is unfortunate.
I vote for a supported version of Dart for the Java folk!
Something like http://code.google.com/p/plywood/.
Something to help us replace Java and Perl/Ruby/Python with a reasonable alternative.
_This comment was originally written by ragas.sagar...@gmail.com_
Even tho it takes little effort convince in new way, I like it ("_") since one can know weather it is private or public by variable name itself. as sad by [email protected] since Features aren't free it is best thing the dart development team did. any how If they are able to keep both features this is good too.
_This comment was originally written by rfab...@planalytics.com_
The first issue request said it well... And since Dart is supposed to be designed with Javascript and Java in mind... Why not make this sensitive aspect include two ways. Of course, I would personally prefer the more Java way... (nuanced a bit toward simplicity), but we grant that Javascript is a significant influence in this new language. So having the underscore seems to be the winner... but also makes for losers... since so many people who do Java everyday will shun this stylistic choice. Just one little compromise by the developers could help... The first issue poster said it well. But I'd like to add one slight adjustment to the proposed "public" or "private" addition. I've noticed that 90% of my class variables are instance variables and should be considered "private". So why not make "private" the default. I know this breaks the Javascript mindset of leaving more things public... so perhaps this won't work. But I'm appealing to some more serious Javascript developers / Dart developers who realized that keeping things private is just good practice. So assuming that is acknowledged, then just have ONE keyword... "public"... since "private" will be assumed. But this leads to the wondering if we can't go even more terse and inventive with syntax... since even "public" is verbose compared to the "Plywood" idea of "variable@" with the "@" denoting public, all this having a connection with the Unix symlink... pretty cool in my mind... pretty weird to others (until they get used to it). Sorry for that dream idea... No. Just "public". And back to more compromises... switch "public" for "private" (with public being the default) if the Javascript-everything public obsession is too strong. At least there would be something other than the bothersome "_" tied to a variable on each occurrence (simply horrible). Yes I'm talking about a declaration keyword (ONE TIME)... But Dart/Javascript have "_" on each occurrence of private! This is just crazy to a Java developer... and makes some of us run screaming from the language.
:+1:
Would love to see visibility modifiers added. Would definitely put Dart on the map for me.
This is too much. No one is hearing these issues. I would like to ditch the Dart now for this weird underscores and unreadable syntax. Dart would be great without these ugly underscores. I would like to say Dart has been failed; at least to please me. Sorry.
@krupalshah Check out Typescript.
Most helpful comment
_This comment was originally written by rfab...@planalytics.com_
This issue is a gentle way of trying to survive using a language that is otherwise pretty nice. This issue of private/public is THE BIG issue that will make Dart not as dominant as it could be. As a Java Developer (and 20 years experience), I know this will be the #颅1 issue that will drive people away from this otherwise very nice language.
Correct way:
Everything private by default with class based privacy.
Use @颅 for properties and public things in a suffix style like unix symlinks.
(Raw values is a much less important use of the important character "@")
PS: (another issue, sorry): Use more lowercase. "foreach" instead of "forEach".
PS2: favor composition more than subclassing. "Allan Holub", Fragile Base class.
PS3: Don't focus so much on Javascript and Java style to exclude other goodies.
(add Perl regex, Ruby constructor syntax, "initialize", C/Perl terseness "fopen")
Take a 10 day open vote showing the two alternatives and some nice examples.
See what the common "people" like.
My 2 cents.
jwait.com