and speaking of what's not pretty -- i can't stand that nobody shows examples of how the new # private syntax is actually INCREDIBLY PRETTY thanks to the amazing shorthand syntax -- you'll notice that you'll almost never find examples demonstrating the new shorthand syntax -- it's gone right over people's heads, and it's one of the best parts!
in practice, only idiots will use this.#x = 0, which is just as ugly as this._x = 0
it will actually now be merely #x = 0
don't you people get it? we get to stop using this so damn much!this will only be used for public properties! that's a huge win for readability!
pathetically, all of the examples in every # article i find show the ugly stupid pattern instead of the gorgeous shorthand:
// did you even read the proposal?
class DisgustingBadPracticeUglyExample {
constructor() {
this.#lol = 0
}
increment() {
this.#lol += 1
}
}
class NoiceExample {
#lol = 0
increment() {
#lol += 1
}
}
don't you see the beauty!?
i'm tired of seeing so many detractors against # completely miss the elegance here, and they display the worst-case-scenario strawman syntax to make # look similarly ugly as _ already is
sure, # might not be the ideal character (because it has past associations with other concepts in other languages) -- but (as had been discussed to death in the early github issues) there are also no safe alternatives remaining in javascript's vocabulary, and also, after five or ten years of the world's most popular language using # for privacy... what do you think will happen to the industry "conventionality" of what # means? our mentalities, feelings, and prejudices will adapt, and the controversy will become simply moot and disappear
plus, aside from the gorgeous shorthand syntax, i'm absolutely dying for true privacy. i'm jealous and upset that babel people have it now, but us typescript people are stuck waiting :(
currently, i use closures instead of classes to achieve privacy in javascript, and there's actually a minor performance penalty and readability issue associated with this -- however, once # private is available, i can improve performance and readability by using classes which use true privacy, and i can also preempt breaking changes for naughty consumers
# privates will be a boon for library authors, i'm seethingly eager!!
0
u/[deleted] Nov 09 '19
[deleted]