Making immutable instances

Mike vimakefile at yahoo.com
Thu Nov 24 11:54:26 EST 2005


<bonono at gmail.com> wrote in message 
news:1132822876.386030.260610 at f14g2000cwb.googlegroups.com...
>
> Mike Meyer wrote:
>> "Giovanni Bajo" <noway at sorry.com> writes:
>> > Mike Meyer wrote:
>> >> Note that this property of __slots__ is an implementation detail. You
>> >> can't rely on it working in the future.
>> > I don't "rely" on it. I just want to catch bugs in my code.
>>
>> I certainly hope you're not relying on it to catch bugs. You should do
>> proper testing instead. Not only will that catch pretty much all the
>> bugs you mention later - thus resolving you of the need to handcuff
>> clients of your class - it will catch lots of other bugs as well.
>>
> That is an ideal case and we all know the real world is not ideal or
> every program would be bug free. And I don't think anyone would solely
> relies on the language feature for spotting bugs. Whether this kind of
> guard is useful is another story.

This is a case where the *language* should be expressive as possible, and 
the *tools* surrounding it should be of more help.
Have I ever mistyped a python variable and introduced a bug? -- many times, 
and it's really annoying. It's a fault that there's no tool that realizes 
that "positon" looks a hell of a lot like "position", more than it's the 
compiler's fault to make such an assumption, because the compiler can't 
"close the loop" with the user, but the tool can. (Or my fault for not using 
such a tool - I know there's pylint, etc.) 





More information about the Python-list mailing list