theme selector

light blue screenshot grey screenshot navy screenshot dark green screenshot red and black screenshot
 

by Tony Chang
tony@ponderer.org

All opinions on this site are my own and do not represent those of my employer.

Creative Commons Attribution License

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 like python’s private 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 __ to _. So instead, I just make everything protected or public.

Now maybe if there were better python refactoring tools I wouldn’t mind so much …

Nikolas Coukouma at Oct 17, 2005, 09:09pm EDT

I would expect Bicycle Repair Man‘s rename refactoring to take care of it.


tony at Oct 18, 2005, 01:48am EDT

I recall trying it a while back and realizing that I would have to adopt emacs, vi or idle as my primary dev environment. Although that’s really my fault for not using a standard editor. I’m not exactly sure what I have in mind as far as a refactoring tool that would work with any editor.