{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/53","repository_url":"https://api.github.com/repos/tc39/proposal-private-fields","labels_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/53/comments","events_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/53/events","html_url":"https://github.com/tc39/proposal-private-fields/issues/53","id":178098425,"number":53,"title":"Consider using private keyword AND sigil for declaration","user":{"login":"dalexander01","id":12902740,"avatar_url":"https://avatars.githubusercontent.com/u/12902740?v=3","gravatar_id":"","url":"https://api.github.com/users/dalexander01","html_url":"https://github.com/dalexander01","followers_url":"https://api.github.com/users/dalexander01/followers","following_url":"https://api.github.com/users/dalexander01/following{/other_user}","gists_url":"https://api.github.com/users/dalexander01/gists{/gist_id}","starred_url":"https://api.github.com/users/dalexander01/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dalexander01/subscriptions","organizations_url":"https://api.github.com/users/dalexander01/orgs","repos_url":"https://api.github.com/users/dalexander01/repos","events_url":"https://api.github.com/users/dalexander01/events{/privacy}","received_events_url":"https://api.github.com/users/dalexander01/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-09-20T15:45:07Z","updated_at":"2016-09-20T17:16:42Z","closed_at":null,"body":"Basically bringing back @wycats proposal: https://github.com/wycats/javascript-private-state\r\n\r\n````\r\nclass {\r\n  private #data1;   // data1 is the name of a private data slot\r\n                    // the scope of 'data1' is the body of the class definition \r\n  constructor(d) {\r\n    // #data1 has the value undefined here\r\n\r\n    // # is used to access a private data slot\r\n    // #data1 is shorthand for this.#data1\r\n    #data1 = d; \r\n  }\r\n\r\n  // a method that accesses a private data slot\r\n  get data() {\r\n    return #data1;\r\n  }\r\n}\r\n````\r\n\r\nI am not going to cover the importance of using the sigil for access as this has been explained ad nauseam in other issue threads.\r\n\r\nI think using the private keyword to indicate privacy and the sigil to indicate how to access fields makes the code easier to read and provides some linting and IDE advantages over just using the # to indicate privacy and access.\r\n\r\nSome call using both redundant but I do not think so at all. \r\n\r\nprivate #data1 simply means that we have a field called data1 that is private, that you access with this.#data1 or #data1. Everything you need to know you can find in the declaration. Where as without the private keyword, readers and coders would have to remember what the sigil means. \r\n\r\nThe sigil doesn't indicate privacy, it only indicates how to access the field. This thought process opens up the possibility for other access modifiers to possibly share sigils if needed. \r\n\r\nFor example:\r\n\r\n````\r\nprivate #field1;\r\nprotected #field2;\r\n````\r\n\r\nHere you have 2 different fields with different access modifiers, but both accessed through the same sigil.\r\n\r\nIt would also lean to more consistent code and make more sense in the case of another access modifier not needing a sigil for access:\r\n\r\n````\r\nprivate #field1;\r\nprotected field2;\r\n````\r\n\r\nvs\r\n\r\n````\r\n#field1\r\nprotected field2;  \r\n````\r\n\r\nI think the above would be totally unintuitive. \r\n"},"comment":{"url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/comments/248368707","html_url":"https://github.com/tc39/proposal-private-fields/issues/53#issuecomment-248368707","issue_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/53","id":248368707,"user":{"login":"dalexander01","id":12902740,"avatar_url":"https://avatars.githubusercontent.com/u/12902740?v=3","gravatar_id":"","url":"https://api.github.com/users/dalexander01","html_url":"https://github.com/dalexander01","followers_url":"https://api.github.com/users/dalexander01/followers","following_url":"https://api.github.com/users/dalexander01/following{/other_user}","gists_url":"https://api.github.com/users/dalexander01/gists{/gist_id}","starred_url":"https://api.github.com/users/dalexander01/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dalexander01/subscriptions","organizations_url":"https://api.github.com/users/dalexander01/orgs","repos_url":"https://api.github.com/users/dalexander01/repos","events_url":"https://api.github.com/users/dalexander01/events{/privacy}","received_events_url":"https://api.github.com/users/dalexander01/received_events","type":"User","site_admin":false},"created_at":"2016-09-20T17:16:42Z","updated_at":"2016-09-20T17:16:42Z","body":"> It's fairly typically to have a default \"access modifier\" in OOP languages, though.\r\n> \r\n> Without the keywords you would need different sigils and end up with sigil soup. I think the above is a lot more readable and to the point.\r\n> That's not true. This is reasonable, I think:\r\n> \r\n> class C {\r\n>   #slot1;\r\n>   unprotected #slot2;\r\n>   constructor(s1,s2) {\r\n>     #slot1 = s1;\r\n>     #slot2 = s2;\r\n>   }\r\n> }\r\n\r\nI assumed due to the nature of this proposal and the fact that there is no corresponding \"public\" keyword that the default visibility would be public as it is today. The public keyword would not require a sigil so it's a moot point. \r\n\r\nMaybe I didn't understand what you mean by \"optional\", but in the code above if the keywords were optional wouldn't this be possible?:\r\n\r\n````\r\nclass C {\r\n   #slot1;\r\n   #slot2; // is slot2 unprotected or private here?\r\n````\r\n\r\n\r\nIn the case of possible private and protected access, if the keywords were optional, you would need 2 different sigils. You would end up with something like\r\n\r\n````\r\nclass A {\r\n   #field1;\r\n   @field2; // or whatever other sigil you want to use for protected\r\n\r\n   constructor(field1, field2) {\r\n      this.#field1 = field1;\r\n      this.@field2 = field2;\r\n   }\r\n}\r\n````\r\n\r\nYou could use a protected keyword instead of sigil, but then it raises the question of why can't we also use the private keyword instead of a sigil? Using a protected keyword and sigil for private makes things inconsistent and less intuitive in my opinion:\r\n\r\n````\r\nclass A {\r\n     protected field1;\r\n     #field2; // wtf why can't I just use private field2 here?\r\n}\r\n````\r\n\r\nSeparating the declaration with an access modifier and a sigil to represent how to access the field, seems to be the most straightforward and most intuitive solution in my opinion."}}
{"actor":{"display_login":"dalexander01"}}