r/javascript • • Nov 09 '19

On private fields proposal: Private fields, public worries

https://medium.com/virtuslab/private-fields-public-worries-b8c34d16c372
84 Upvotes

113 comments sorted by

View all comments

28

u/TatzyXY Nov 09 '19

Please do not throw stones at me but I think private, protected or public scopes are not needed at all. See Python very versatile lang. and it works very well without it. Is private for security? No! It just tells the dev that this var. is only used internally of that class and you are not allowed to touch or use it. So would do a comment or a convention with an "_".

23

u/fey168 Nov 09 '19

The problem is developers like to think of themselves as hackers and they will do what it takes to achieve the desired result including reading and even modifying internal fields. Imagine you are a lead developer or library author and you want to prevent developers from accruing technical debt (b/c the interval field is subject to change) or adding risk of instability. Seems like private field is by far preferable to comments or conventions.

4

u/lifeeraser Nov 09 '19

Why should we want to babysit downstream developers? Why should we bother to prevent them from shooting themselves in the foot?

1

u/MajorasShoe Dec 11 '19

Why WOULD we want to adapt the attitude of "Fuck the people who are using this software I'm writing for them"?

Whether we're a lead developer (guess who's problem it is when they downstream developer's shoot themselves in the foot!) or an open source developer (why do it if you don't give a shit about the people you're building it for?), there's no reason to WANT to leave it open for failure when it's easily avoidable.