4 ms·
I've always felt that going out of your way to enforce information hiding in programming was kind of silly. Establish in your documentation what is public and w
by mistercow 15y ago
I've always felt that going out of your way to enforce information hiding in programming was kind of silly. Establish in your documentation what is public and what is private and then don't worry about it. If someone wants to hack on your private variables, you aren't going to stop them with this or any other pattern, and if they want their code to work properly, a comment that says "private" will tell them what not to mess with.
- Lazare 15y agoAgreed, completely. And if you want to go further, a convention that anything starting with an underscore is private, and probably shouldn't be accessed or called without good reason and the understanding that it may break or change at any time is a good idea. (This is how Python works.) In the real world, enforcing information hiding isn't really useful.
- ronaldj 15y agoWhat if you want a clean API? What if you want the users of your code to be able to instantiate an instance and inspect that object in the console, seeing only the public methods and not having them get lost in a sea of private stuff?
- bcrescimanno 15y agoFWIW, If you want instantiate-able objects, the module pattern is probably the wrong option in that case anyway.
- andybak 15y agoHmmmm. The Python convention of semi-private methods starting with an underscore would do the trick. I've been burnt in the past with using someone else's javascript code and finding out that something I needed to modify they hadn't deemed public for some weird reason. Forking the code isn't the best pattern for code reuse.