loose methods : Smalltalk asPython

Steven D'Aprano steve at REMOVEME.cybersource.com.au
Wed Dec 27 22:04:33 EST 2006


On Wed, 27 Dec 2006 09:28:17 -0500, Jean-Paul Calderone wrote:

> On Wed, 27 Dec 2006 19:03:12 +1100, Steven D'Aprano <steve at remove.this.cybersource.com.au> wrote:
>>
>>You can't modify the built-in classes. I'm not sure that it is a good idea
>>to allow built-ins to be modified. When I see an int, I like the fact that
>>I know what the int can do, and I don't have to worry about whether it has
>>been modified by some piece of code elsewhere.
> 
> I wonder how this is different from any other class.  If you see a StringIO
> or a socket, don't you also expect to know what it can do?  But in fact you
> _do_ have to worry about whether it has been modified, at least according
> to your argument.

Yes. It is a trade-off: the more flexibility you have to modify classes
and instances at will, the less you can take for granted. The more
that classes are locked down, the more you can take for granted.

Personally, I am quite comfortable with the Python tactic of locking down
built-in types like int, and leaving user-defined classes more open.
Yes, there is some risk that some piece of code has modified StringIO in
unexpected ways. But the risk is moderate, and it doesn't apply to the
most basic object types like ints and strings. That feels like the right
level of risk to me. Others might disagree, and prefer a language which is
more restrictive, or less restrictive. To each their own.



-- 
Steven D'Aprano 




More information about the Python-list mailing list