Monday, 25 November 2013
Private and Classy
Private classes are now a thing in Python! Kinda. Not really but we at least now have a way to prevent people from easily tampering with our variables. They can still do I: just not easily. This is all thanks to the built in 'property' which takes 4 values. The first two are what you'd like to be the get and set methods for this variable. They can literally be anything (that compiles) but ideally they should return a copy of the requested variable and allow you to change said variable within the appropriate restrictions. The next parameter the property takes is delete. When attempting to delete this variable this is what is called. I wonder if by simply passing you could make your variable very hard to Delete. Lastly you can add read only docstring. At first I didn't see the point if your method already has docstring but then I realized that it might be useful to have docstring specific to the user to give him/her more relevant information ( or so that we're able to call the user funny names behind his back)
Subscribe to:
Post Comments (Atom)
By making it hard to delete you mean throwing an exception every time delete is called? "Exception: I AM AN IMMORTAL OBJECT"
ReplyDeleteOr even making the Object INCREASE in size every time you try to delete it! Mwahahahahahaha!
DeleteThis comment has been removed by the author.
ReplyDeleteI guess it is slightly harder to tamper with someone‘s code now (but still not difficult).I
DeleteIts kinda a thing indeed
Interesting point on adding the read-only docstring.