-
Notifications
You must be signed in to change notification settings - Fork 113
Use both the # sigil and keywords #61
Comments
See previous discussion, or this recent comment in a different repository for a summary. I suppose it may be worth adding this to the FAQ too. |
|
We should probably also reference the protected decorator story as well as the way that you can use ordinary symbols for protected in the FAQ. It has been explained on several bug threads. |
@littledan you can also use ordinary symbols for private, so why do we need this proposal? I hope this is not seriously your suggestion:
🤮 |
@lpd-au no, symbols are 100% public, because of Object.getOwnPropertySymbols. “private“ means it’s impossible to access it or even learn of it’s existence, by any means. |
@lpd-au yes, that's the idea. What's the problem? Too much punctuation? |
It's an absolute dog's breakfast of symbols and keywords, yes. There is zero consistency, it completely fails the least astonishment test and for you most importantly: no level of exposure/familiarity would ever make it appear as more than a bad hack. Can you provide me with an example of the boilerplate code that would be necessary to make
If you want to be pedantic, sure, you have to use a weakmap for 100% privacy. But that means the point I was replying to, "that can use ordinary symbols for protected," is equally incorrect. My point is that there is no reason why protected should be a second class citizen. Just because it can be done in other ways, doesn't mean an inbuilt, cleaner and more user-friendly way shouldn't exist; we wouldn't have the class syntax at all otherwise. |
@lpd-au, see previously and elsewhere on the topic of |
@lpd-au is it boilerplate to import a library? We could later add this as a built-in contextual keyword if needed. |
If it's to import something as fundamental as a reserved keyword, I'd probably actually have to argue yes, it is. You haven't answered either of my questions though. |
Please see friends.js in this repository for a possible library definition of protected. As for why one is OK and not the other: there is a lot written about why the # is necessary and why strong privacy barriers are a goal. From there, private is a necessary default and more text is redundant. Protected does not offer any more privacy than symbols, which are already available. |
There isn't one, but I assume you mean friend.js in the decorators repository, thanks.
Your conclusions don't follow the premise:
All of the clear double standards being applied here seem to boil down to this: if developers could only pick one, we'd opt for private over protected. That should not be used as justification to select a restrictive, unfriendly and ugly syntax. I imagine the original purpose of decorators at the start applying to all following comma separated fields was precisely so they could implement hacks like
With the keyword out the front, I see that confusion significantly diminished. At least it doesn't seem any more ambiguous than |
@lpd-au "hard private" is both a necessary feature and default. "protected" would not provide any privacy because you could trivially observe it by making a subclass and using that to do so. |
Even if the concept of finality is never formally added to the syntax:
I'd say that's offering more privacy than symbols, but I'm happy to learn something and be proven wrong. |
@lpd-au B/B.prototype is fully accessible from the prototype chain of C/C.prototype; you don’t have anything private there whatsoever (just like if you used Symbols). |
With respect to all the thought and debate that led to this point, I completely agree. Reading the FAQ and comments it feels like the rationale for the magic syntax and against the keyword seems to be inconsistent, and shifts slightly depending on what part you're reading. Frankly I think we have yet to find an actually good solution, I hope this isn't over. |
Seems like we didn't really arrive at a change we want to make in this thread. We've been talking about |
For the record, I find the syntax of this proposal to be awful and hope it's rejected in its current form. However, considering this seems likely to be pushed through regardless of overwhelming feedback, I'd like to suggest an amendment to make it slightly more palatable.
Basically: keep the hash to distinguish between public and non-public property names but use keywords before their declaration. Yes, this is slightly more verbose. However, the code's effect is significantly more clear to the reader. At worst, a newcomer might wonder why the author chose to name all their non-public variables with a leading hash, instead of currently mistaking it for a comment line. It's also alot more flexible; how does the current proposal allow for future extensions such as protected? This extensibility is imo a key advantage.
(Ideally, this principle would be applied but with an underscore instead of a hash. I've read the FAQ but the section regarding runtime checks on the receiver is completely unsubstantiated, and the section below that regarding lack of static types is nonsense [eg PHP manages just fine]. But I digress...)
The text was updated successfully, but these errors were encountered: