Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Why not use private keyword instead of #? #8

Closed
cathrinevaage opened this issue Jul 28, 2017 · 7 comments
Closed

Why not use private keyword instead of #? #8

cathrinevaage opened this issue Jul 28, 2017 · 7 comments

Comments

@cathrinevaage
Copy link

I'm sure you have taken this into account somehow, but I can't find discussion or reasoning for it in my research.

Why use the # prefix?
Why not use the private keyword?

I'd imagine you would use it somewhat like this:

class Foo {
  private bar() {
    // ...
  }

  constructor() {
    private.bar();
  }
}

Here we use the private keyword, both when defining the method, and when referencing the it.

As far as I can tell, this would solve the problem of having them being accessible on the instance of the class.

We already do something similar when referencing methods of a superclass, using the super keyword.

I find this to be more expressive, and more familiar.

@bakkot
Copy link
Contributor

bakkot commented Jul 28, 2017

See the FAQ for private fields.

@alexprice1
Copy link

@bakkot why not prevent there from being a public field if a private field exists?

@bakkot
Copy link
Contributor

bakkot commented Sep 28, 2017

@alexprice91 See the FAQ for private fields.

@andy9775
Copy link

andy9775 commented Oct 2, 2017

#myMethod is just weird.

@bakkot
Copy link
Contributor

bakkot commented Oct 2, 2017

@andy9775 We have heard that observation previously, yes.

@aaronbeall
Copy link

aaronbeall commented Dec 19, 2017

If the point is to avoid confusion with Java's private x and this.x why not use a different keyword like local x? Using #x and x() (no hash) is itself a potential source of confusion and bugs, and we are used to keywords already (static, async, await).

@littledan
Copy link
Member

See this FAQ entry for more details on why no prefix will make it work. For better or worse, it seems like we'll stay with # syntax.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants