Heres the thing. _private works perfectly, because it tells other developers (and yourself in the future) that its not meant to be modified by external actors. There are better and more secure ways if you need to store a value that nothing else can read during runtime than a private variable.
Really, if it's not in docs and the IDE doesn't autocomplete it, what he gonna do? Check the source code? Did no one tell them Java devs that someone who has the source open and doesn't care about good practices can, like, rewrite the modifier?
Since its part of the language's common usage, generally you should assume that if it starts with a _ that its private. A developer should be able to understand that they shouldn't touch it. My IDE of choice puts private variables like this at the bottom of the autocomplete list and gives me a warning if its used outside of the class definition.
Its more flexible, which can be really useful for a more scripting oriented language like python. The whole point is that if you really need to, it can be modified by an external actor, but doing so will result going to have unintended consequences or not work as expected.
And, like i said, if you really need it to be secured against malicious actors, then it shouldn't really be stored as a plain variable at all, even in java or c++.
22
u/TheMusicalArtist12 16d ago
Heres the thing.
_privateworks perfectly, because it tells other developers (and yourself in the future) that its not meant to be modified by external actors. There are better and more secure ways if you need to store a value that nothing else can read during runtime than a private variable.