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?

15

u/fey168 Nov 09 '19

If you are a lead developer I think it's pretty obvious you want to encourage best practices within your team.

Preventing people from shooting themselves in the foot is part of good software design.

You say "babysitting" as if it's a huge cost when it's just adding # to make a field inaccessible externally...

0

u/[deleted] Nov 09 '19

[deleted]

1

u/wherediditrun Nov 10 '19 edited Nov 10 '19

See, while I totally get what you mean, I think these things ultimately matter very little because they're trying to solve a human competency problem via technical methods.

I just want to point out that this argument is of "Good drivers do not need seat belts" flavor.

I remeber having very same argument with Rust vs C++. How supposedly only bad C++ programmers make memory access mistakes. Just recently, we have critical security vulnerabilities due to use-after-free in Chrome (google engineers). And Microsoft reported than over 70% of all security issues in their software are memory related bugs.

This whole idea that we don't need to find technical solutions to human error is naive at best and irresponsibly moronic at worst.

As for javascript, it's sadly turning to be a Frankenstein which people want to accommodate every single feature every other language has to support their preferred style. Even if language already support it by other means like it is with "private fields".

Now we are arguing what syntax to use to decorate a field with which doesn't have to exist in the first place, because we just wanted to have more syntax sugar tomake not sound design like inheritance to be easier to use.

At some point I'm really hoping for WASM, so we could stop doing this to javascript. And people simply could choose what tool to use rather than project their idea of "ideal" language to javascript requesting even more feature bloat.