By bloid
via codethinked.com
Published: Nov 09 2007 / 11:32
Recently I came across this post on www.builderau.com.au. The article is talking about how the author was attempting to figure out how to put a private variable onto a class in Python and how his efforts were fruitless. And so, like any good programmer, he questions the very need for a feature that isn't in his language of choice. And also, like a good programmer, I *completely* disagree with him. Now before I get into this rant, be aware that I do not know the author in question and I have nothing against him, I simply to not agree with him.
Comments
Nick Brown replied ago:
Python isn't Java or C#. Its not that it simply has a different set of features or a different looking syntax, it is a completely different animal. You cannot write a Python program with the same mindset as when you are writing a Java or C# application. If your approach to Python (or other similar languages like Ruby) is to just do whatever it is you would do in a Java app except with Python syntax, you have completely missed the point.
BTW, encapsulation is possible in Python, even without the private keyword. What isn't possible is to have the compiler/interpreter enforce that encapsulation by refusing to build or crashing if someone attempts to bypass that encapsulation.,
dzonelurker replied ago:
Well said.
justin_etheredge replied ago:
I completely agree that Java and C# are very different from Python. No better or worse, just different. I'm not attacking Python, I am just saying that the author took something that is lacking in python and tried to make it something to be proud of. If the authors of Python had not thought that encapsulation at some level was necessary they would not have added the double underscore syntax for restricting access to variables (although this doesn't restrict access, it just changes their name so that they are harder to access by accident). I did address your comments on my post though.,
FlySwat replied ago:
Well said.
Ryan Ginstrom replied ago:
Good article. I don't agree 100%, but it's well argued and thought-provoking.
jober replied ago:
I think the author misses the point. The lack of private attributes in Python is not a feature nor a deficiency; it's a difference in philosophy. Encapsulation is not threatened by public methods. So long as documentation is good, the convention of naming internal variables/methods with an underscore will (hopefully) ensure that their use externally is done with prudence. Trust that other programmers know what they are doing. If they don't, then there is little you can do to fix the problem in any case.
Voters For This Link (18)
Voters Against This Link (2)