Re:Dear Python
by jmillikin on Tuesday February 02, 2010 @07:36PM
(#1096702)
Placing 'self' in the parameter list allows external procedures to be monkey-patched into a class, without needing to wrap it up in a 'partial'. For example:
While this is ugly, there are times when augmenting (or replacing) a class's existing methods is useful.
[ Parent
| on HN ]
I have found it very useful when writing unit tests for a particular method. I don't have to instantiate the class for which the method is a member of; instead I can easily pass a mock object as self that only contains the properties the method is supposed to test.
Furthermore the claim that python doesn't support objects cleanly or easily is unfounded: 1) everything is an object in python (http://diveintopython.org/getting_to_know_python/everything_...), including classes. 2) properties of an object are accessed in just the same way as in Java (obj.property), I don't understand where the confusion lies.