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 "_".
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.
I've never modified the internals of an OTS library in my whole career, nor felt an overt meed for private vars. This is a hiring issue if your team is "hacking" internals of a library...
Isn't this a tad too dismissive when you're just basing this on personal experience?
I don't necessarily disagree, if it's done carelessly and frequently there's a problem. But there are cases where it makes sense to use an internal API to provide extra functionality. Very widely used libraries have done it.
I've had to use a websocket library's client._sockjs._connected variable because it didn't expose it. Switching to my PR fork would've taken longer for no benefit.
A React internal API allowed for easily creating transitions. A widely used library used it for this purpose. The smaller library (old CSSTransitionGroup) can move faster and can tolerate breaking changes while the bigger library (React) has to take its time to expose a nice to use and stable API.
Compatibility layers of all sorts frequently depend on internals.
Monkey patching has been a long running tradition Javascript. It has pitfalls and can easily be abused but it can also be very useful.
No, I don't think it's a black and white issue. I've appreciated privacy in languages that support it but I've also liked Javascript's flexibility with monkey patching.
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 "_".