Link Details

Link 51875 thumbnail
User 111696 avatar

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.
  • 18
  • 2
  • 1609
  • 596

Comments

Add your comment
User 254602 avatar

Nick Brown replied ago:

1 votes Vote down Vote up Reply

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.,

User 236137 avatar

dzonelurker replied ago:

0 votes Vote down Vote up Reply

Well said.

User 257143 avatar

justin_etheredge replied ago:

0 votes Vote down Vote up Reply

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.,

User 238564 avatar

FlySwat replied ago:

0 votes Vote down Vote up Reply

Well said.

User 251813 avatar

Ryan Ginstrom replied ago:

0 votes Vote down Vote up Reply

Good article. I don't agree 100%, but it's well argued and thought-provoking.

User 253983 avatar

jober replied ago:

1 votes Vote down Vote up Reply

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.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.