[Python-Dev] Re: Alternative implementation of string interning

Ka-Ping Yee ping@zesty.ca
Tue, 2 Jul 2002 23:07:14 -0700 (PDT)

Oren Tirosh wrote:
> Why not make interned strings a type?  <type 'istr'> could be an
> un-subclassable subclass of string.  intern would just be an
> alias for this type.  No two istr instances are equal unless they are
> identical.  I guess PyString_CheckExact would need to be changed to
> accept either String or InternedString.

The possibility of people starting to write code that depended on
whether strings were 'string' or 'istr', and all the breakage and
incompatibility that would result, seems much too ugly to contemplate.
Pass an 'istr' into a routine that expects strings, and it would
appear to be a string right up until someone tried to == it, whereupon
all hell would break loose.

The acid test for subtyping is substitutability: type 'istr' would not
fulfill the contract of 'string', and neither would 'string' fulfill the
contract of 'istr'.  Therefore, if you really wanted to do this, your
new type (let's call it 'symbol') would have to be completely independent
from both strings *and* interned strings.  There's no subclass relationship.

-- ?!ng