python access levels
Oct 17, 2005, 05:48pm EDT
In Effective Java, Joshua Bloch writes:
The rule of thumb is that you should make each class or member as inaccessible as possible. In other words, you should use the lowest possible access level consistent with the proper functioning of the software that you are writing.
I think this is good advice because it’s easier to add functionality later
(converting a method from private to protected) than it is to take it away or
change it. But when I look at the python code I write, I find that I almost
never make methods or variables private. It finally dawned on me why I don’t
variables: it’s too hard to convert from private to protected.
In Java or C++, you just change a keyword from private to protected, but in
python, you have to find and replace all method calls from starting with
_. So instead, I just make everything protected or public.
Now maybe if there were better python refactoring tools I wouldn’t mind so much …