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

Add a keyword for private scope in libraries #520

Closed
DartBot opened this issue Nov 18, 2011 · 12 comments
Closed

Add a keyword for private scope in libraries #520

DartBot opened this issue Nov 18, 2011 · 12 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 type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 18, 2011

This issue was originally filed by potoms....@gmail.com


https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/a0cdcd2872d4c5eb/e1d6b834bd25533e

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.

@DartBot
Copy link
Author

DartBot commented Nov 22, 2011

This comment was originally written by drfibonacci@google.com


Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Dec 14, 2011

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.

@DartBot
Copy link
Author

DartBot commented Apr 5, 2012

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

@DartBot
Copy link
Author

DartBot commented Apr 5, 2012

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.

@DartBot
Copy link
Author

DartBot commented Sep 15, 2012

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!

@DartBot
Copy link
Author

DartBot commented Oct 18, 2013

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.

@DartBot
Copy link
Author

DartBot commented Oct 18, 2013

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.
    

@DartBot
Copy link
Author

DartBot commented May 22, 2015

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 gbracha@google.com 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.

@DartBot
Copy link
Author

DartBot commented May 22, 2015

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.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels May 22, 2015
@atrauzzi
Copy link

👍

Would love to see visibility modifiers added. Would definitely put Dart on the map for me.

@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
@krupalshah
Copy link

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.

@atrauzzi
Copy link

@krupalshah Check out Typescript.

copybara-service bot pushed a commit that referenced this issue Dec 14, 2022
Revisions updated by `dart tools/rev_sdk_deps.dart`.

browser_launcher (https://github.com/dart-lang/browser_launcher/compare/5fa0bd6..2712dda):
  2712dda  2022-12-13  Anna Gringauze  Fix internal CI test failures (#35)

dartdoc (https://github.com/dart-lang/dartdoc/compare/eb90a44..1f42216):
  1f422163  2022-12-13  Sam Rawlins  Bump to 6.1.5 (#3274)

intl (https://github.com/dart-lang/intl/compare/234b291..6fb07f2):
  6fb07f2  2022-12-14  Copybara-Service  Merge pull request #520 from dart-lang:revto18
  1f9815c  2022-12-14  Moritz  Rev version in preparation for publish of 0.18.0
  1d37c42  2022-12-13  Googler  Internal change
  708b85c  2022-12-13  Copybara-Service  Merge pull request #498 from dart-lang:remove_intl_stream
  2d9eca9  2022-09-28  moritz  sort imports
  08a35bd  2022-09-28  moritz  Merge branch 'master' into remove_intl_stream
  0fc6ab9  2022-09-28  moritz  Changes as per review
  4680742  2022-09-27  moritz  rename to stack
  f687c72  2022-09-27  moritz  changes as per review
  ef36013  2022-09-26  moritz  add reference to benchmark
  117c0cf  2022-09-26  moritz  separate read and pop
  434378a  2022-09-26  moritz  move method
  e98c4aa  2022-09-26  moritz  fix typo
  9234540  2022-09-26  moritz  rename file
  024cffc  2022-09-26  moritz  make it a tad faster
  c6f7b6a  2022-09-26  moritz  some renaming
  443c9e0  2022-09-26  moritz  Remove StringIterator
  1953002  2022-09-23  Nate Bosch  Inline the extension
  4dfdc1b  2022-09-22  Nate Bosch  Simplify the IntlStream class

mime (https://github.com/dart-lang/mime/compare/c0c4c47..273d454):
  273d454  2022-12-13  tomk9  Add .dcm to extension map (#74)
  aacec32  2022-12-12  Kevin Moore  Update to latest lints, bump min SDK to 2.18 (#77)
  536db4f  2022-12-12  Kevin Moore  blast_repo fixes (#79)
  2343229  2022-12-12  Kevin Moore  Add .msj (and change .js) to text/javascript (#76)

mockito (https://github.com/dart-lang/mockito/compare/347d3e4..942dd03):
  942dd03  2022-12-12  yanok  Override `SmartFake.toString` to be super-verbose
  5f97a43  2022-12-09  Sam Rawlins  Stop using deprecated analyzer APIs
  0660e61  2022-12-06  yanok  Generate method overrides even then source lib is not null-safe
  cf7d851  2022-12-06  yanok  Add override for `Object.operator==` in `SmartFake`
  6b89e99  2022-12-02  yanok  Automated g4 rollback of changelist 492410078.
  d11d010  2022-12-02  yanok  Generate method overrides even then source lib is not null-safe

sse (https://github.com/dart-lang/sse/compare/d396145..cfa93b1):
  cfa93b1  2022-12-14  Elliott Brooks (she/her)  Add `package:js` to dependencies (#71)
  00335e4  2022-12-13  Elliott Brooks (she/her)  Update `package:sse` to `4.1.2`(#70)

webdev (https://github.com/dart-lang/webdev/compare/3e2364e..317288a):
  317288a  2022-12-14  Derek Xu  Remove ChromeProxyService.setExceptionPauseMode() (#1820)
  bbe7143  2022-12-14  Elliott Brooks (she/her)  Migrate `events_test.dart` to null-safety (#1819)
  1d1c98f  2022-12-14  Elliott Brooks (she/her)  Settings page, Dart Debugger panel, and Flutter Inspector panel match DevTools styles (#1815)
  a9b8887  2022-12-13  Elliott Brooks (she/her)  Update tests that are incompatible with `3.0.0` (#1817)

Change-Id: I08e555dc22e5577740fe43e91ff31e4601ac15f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275781
Commit-Queue: Nate Bosch <nbosch@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
copybara-service bot pushed a commit that referenced this issue Feb 20, 2023
…ath, pool, source_maps, test, tools, webdev

Revisions updated by `dart tools/rev_sdk_deps.dart`.

args (https://github.com/dart-lang/args/compare/b08471e..9305d5a):
  9305d5a  2023-02-15  Naoto Kaneko  Update README.md (#236)

characters (https://github.com/dart-lang/characters/compare/29f3a3e..3281cc7):
  3281cc7  2023-02-16  Devon Carew  blast_repo fixes (#75)

dartdoc (https://github.com/dart-lang/dartdoc/compare/3931595..dba6f94):
  dba6f946  2023-02-16  Janice Collins  Preserve type aliases for records in output (#3340)
  96e61903  2023-02-16  Sam Rawlins  Remove unused additionalOptions parameter, other little refactorings (#3339)
  f64290e1  2023-02-13  Devon Carew  remove an unused css attribute (#3335)
  c055526a  2023-02-13  Devon Carew  fix an issue where we created a temporary directory when performing a dry run (#3334)
  1f6c8db5  2023-02-13  dependabot[bot]  Bump github/codeql-action from 2.2.1 to 2.2.4 (#3337)
  f1fa0efc  2023-02-13  dependabot[bot]  Bump actions/cache from 3.2.4 to 3.2.5 (#3338)

ffi (https://github.com/dart-lang/ffi/compare/69d7596..32f5eef):
  32f5eef  2023-02-20  Daco Harkes  Bump SDK constraint to 4.0.0 (#185)

http (https://github.com/dart-lang/http/compare/f4b365e..c13a3f8):
  c13a3f8  2023-02-17  Alex Li  ✨ Add Cronet embedded tool (#853)

markdown (https://github.com/dart-lang/markdown/compare/f51c24c..4befe66):
  4befe66  2023-02-16  Zhiguang Chen  Do not generate heading IDs for headings with no content in `HeaderWithIdSyntax` (#522)
  cae08af  2023-02-15  Kevin Moore  Prepare to release v7.0.1 (#520)
  bdbaf76  2023-02-15  Zhiguang Chen  Remove lookarounds from autolink extension patterns (#519)
  eb09fac  2023-02-14  Kevin Moore  Move to pkg:dart_flutter_team_lints (#518)
  51a6389  2023-02-15  Zhiguang Chen  Add line endings to HTML blocks (#512)
  a4cd7a0  2023-02-14  Kevin Moore  Label tests that only run on the VM: allows running tests with browser (#516)
  6788042  2023-02-14  Kevin Moore  CI: add publish and response workflows (#517)

mockito (https://github.com/dart-lang/mockito/compare/d2a8df1..ed5bd84):
  ed5bd84  2023-01-09  Ross Wang  Relax mixin criteria
  781752c  2023-02-13  Sam Rawlins  Change `void` to `dynamic` when overriding method arguments
  71e41b9  2023-02-10  Sam Rawlins  Add `ignore_for_file: use_of_void_result`
  d5a25f8  2023-02-08  Sam Rawlins  Fix violations of `unnecessary_parenthesis` lint

path (https://github.com/dart-lang/path/compare/a95f1e9..24b58a2):
  24b58a2  2023-02-20  Kevin Moore  Move to team lints, require Dart 2.19 (#138)
  8ec8ca0  2023-02-18  Kevin Moore  blast_repo fixes (#137)

pool (https://github.com/dart-lang/pool/compare/51f1131..694cfd8):
  694cfd8  2023-02-20  Kevin Moore  move to package:dart_flutter_team_lints, require Dart 2.19 (#65)
  40bf2af  2023-02-20  Kevin Moore  blast_repo fixes (#64)

source_maps (https://github.com/dart-lang/source_maps/compare/cf44db3..a112e98):
  a112e98  2023-02-16  Devon Carew  configure publishing automation (#74)

test (https://github.com/dart-lang/test/compare/b5e70db..e56c643):
  e56c6439  2023-02-17  Jacob MacDonald  Add exe compiler, supports running tests compiled to native executables (#1941)
  f80dfa00  2023-02-16  Nate Bosch  Add note about why we are replacing matcher (#1940)
  732ae1de  2023-02-15  Nate Bosch  Add `because` usage in examples (#1939)
  f6df9756  2023-02-15  Jacob MacDonald  Fix typo in readme (#1937)
  aca53419  2023-02-14  Nate Bosch  Add a caret constraint for matcher (#1927)
  f7f3a019  2023-02-14  Jacob MacDonald  use test_api/backend.dart instead of test_core/backend.dart (#1936)
  de40c1c0  2023-02-14  Jacob MacDonald  Add support for `--compiler` flag (#1903)
  1f42db8c  2023-02-13  Devon Carew  updates to package:checks docs (#1933)

tools (https://github.com/dart-lang/tools/compare/48a544b..a53933c):
  a53933c  2023-02-17  Elias Yishak  [package:dash_analytics] Tests for conforming to GA4 Measurement Protocol limitations (#9)
  c54430b  2023-02-17  Devon Carew  add some clarification to the top-level readme (#8)

webdev (https://github.com/dart-lang/webdev/compare/0bae2be..ae7eb80):
  ae7eb80  2023-02-17  Anna Gringauze  Add tests for object inspection (#1973)
  7d80a2c  2023-02-17  Elliott Brooks (she/her)  Ignore offset / count if an instance has no `length`  (#1972)
  cd66172  2023-02-17  Elliott Brooks (she/her)  [MV3 Debug Extension] User can reload app and continue to debug (#1968)
  8b7f9d3  2023-02-16  Anna Gringauze  Re-enable weak webdev tests (#1960)
  83d8e47  2023-02-16  Elliott Brooks (she/her)  [MV3 Debug Extension] Variables in panel.dart should be private (#1969)
  4e85e74  2023-02-16  Elliott Brooks (she/her)  [MV3 Debug Extension] The new debug extension can be run on Manifest V3 or Manifest V2 (#1966)
  3982f5f  2023-02-15  Elliott Brooks (she/her)  [MV3 Debug Extension] Clean up tests in preparation for supporting compiling to MV2  (#1964)
  3ad544e  2023-02-15  Elliott Brooks (she/her)  [MV3 Debug Extension] Remove isMV3Extension field from DevtoolsRequest (#1963)
  c77043e  2023-02-14  Elliott Brooks (she/her)  [MV3 Debug Extension] Fix isDevMode getter (#1962)
  a761125  2023-02-14  Elliott Brooks (she/her)  [MV3 Debug Extension] Print `console` messages on test failure (#1961)
  41e92be  2023-02-14  Anna Gringauze  Create test_common package (#1945)
  443f820  2023-02-14  Anna Gringauze  Re-enable skipped reload test (#1958)
  a7bc3fc  2023-02-14  Anna Gringauze  Make dart-uri-file-uri test use sound null safety (#1959)
  464a8eb  2023-02-14  Elliott Brooks (she/her)  [MV3 Debug Extension] Compile extension with Dart instead of shell script (#1954)
  7cf8fe2  2023-02-13  Anna Gringauze  Fix asset handler tests (#1956)
  c371ad7  2023-02-13  Anna Gringauze  Fix chrome_proxy_service tests broken after switch to null safety by default (#1957)
  d6ec127  2023-02-13  Anna Gringauze  Move test-only code from the SdkLayout (#1955)
  35fa34b  2023-02-13  Elliott Brooks (she/her)  [MV3 Debug Extension] Update Chrome APIs to be backwards compatible with MV2 (#1951)

Change-Id: I4250594d0fa775d07cb3a0f8594e634552de452b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284240
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This issue was closed.
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 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants