-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Public Private and the Underscore - A big issue #2461
Comments
This comment was originally written by rfab...@planalytics.com This issue is a new perspective on a previous issue that was closed (issue #520). http://code.google.com/p/dart/issues/detail?id=520
The new perspective is this: There would be three choices:
Take the "pepsi, coke, and alternative brand" to the public and do a "taste test". (Include a fair set of examples for each brand). NOTE: When you building a larger code base you will notice almost everything is Let the people decide. |
Added Area-Language, Triaged labels. |
This is indeed a big issue. Privacy is pretty fundamental to the language and we are committed to the core elements of the Dart design. This is not something you can mix and match: that is, supporting multiple approaches carries considerable risk of a train wreck. Different approaches require different runtime support and introduce different styles and idioms. We work hard to accommodate mainstream programmer preferences, but in many cases, the mainstream forks. This is one of those cases, and one makes a choice. The issue has come up before, and it is too fundamental to change. |
I can't understand why this issue has been closed. Indeed, we need a new visibility model at least better than writing underscores. As said
Yes, Indeed. I would rather like to learn swift. At least they did right choice with public, private and internal. From the specification :
Maybe it is good for machines, but for humans; writing underscore every time is tedious and far from 'readable'. All we need a new visibility model in 2.0 . |
It's closed because there is nothing to do. int _someVar;
int get someVar() => _someVar;
int set someVar(int value) {
if(value < 0) throw 'only positive values are allowed';
_someVar = value;
} |
Coming from Java, C#, Swift, its very strange to see underscores everywhere to define the whole privacy model of a language. It is not natural for humans reading words prefixed with underscores. It makes the code difficult to read. Swift has a great way to do it: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html @zoechi Why the setter have a return type if it is basically a void function? int set someVar(int value) {
if(value < 0) throw 'only positive values are allowed';
_someVar = value;
} @zoechi Why the need to differentiate someVar from _someVar? Why not have an implicit/internal field with the same of the getter/setter? get int someVar => someVar + 10;
set someVar(int value) {
if(value < 0) throw 'only positive values are allowed';
someVar = value; // this is a special case where the real setter is not called
} |
@andreabreu-me You don't need a return type for setters, actually you shouldn't add one I think the whole underline for private discussion is about 3+ years too late. |
Underscores are ugly, please change. |
This issue was originally filed by rfab...@planalytics.com
The "_" issue again.
This may be the number one issue slowing down Dart popularity.
After 20 years coding in C,C++,Java,Javascript,Perl, I am
surprised this convention won the battle for public/private syntax!
Please consider a 10 day vote to see what the "common people" want.
Make some examples to demonstrate a fair comparison.
Suggestions:
Everything private by default with class based privacy.
Use @ for anything public (properties,methods,class)
Use @ in a suffix style like unix symlinks (name@) (unix ls)
A "struct" would be classname@ so all fields are public.
(Raw values are less important for the important character "@")
PS: Use more lowercase. "foreach" instead of "forEach".
PS2: Favor composition more than subclassing (GoF/Artima).
("Allan Holub", Fragile Base class, Google noop lang)
(build libraries with composition to teach how to do it)
PS3: Use more terseness like C/Perl/Python/Ruby "fopen", etc
PS4: Get good terse Perl like regex working better.
(Help Java coders replace scripts first, Java later)
PS5: Use a Ruby like constructor syntax, "initialize".
I know there are reasons for "", making things explicit, performance,
but first impressions to Java Developers is really important also.
Java Developers can handle something different and creative,
but not "" for private.
jwait.com
The text was updated successfully, but these errors were encountered: