[Python-Dev] String views

Guido van Rossum guido at python.org
Thu Sep 1 16:48:32 CEST 2005


On 8/31/05, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> skip at pobox.com wrote:
> 
> > Ah, I forgot the data is part of the PyString object itself, not stored as a
> > separate char* array.  Without a char* in the object it's kind of hard to do
> > views.
> 
> That wouldn't be a problem if substrings were a separate
> subclass of basestring with their own representation.
> That's probably a good idea anyway, since you wouldn't
> want slicing to return substrings by default -- it
> should be something you have to explicitly ask for.

You all are reinventing NSString. That's the NextStep string type used
by ObjC. PyObjC bridges to NSString with some difficulty. I have never
used this myself, but from Donovan Preston I understand that NSString
is just a base class or an interface or something like that and many
different implementations / subclasses exist. Donovan has suggested
that we adopt something similar for Python -- I presume in part to
make his life wrapping NSString easier, but at least in part because
the concept really works well in ObjC.

I'm not saying to go either way yet. I'm wary of complexifications of
the string implementation based on a horriffically complex
implementation in ABC that was proven to be asymptotically optimal,
but unfortunately was beat every time in practical applications by
something much simpler, *and* the algorithm was so complex that we
couldn't get the code 100% bugfree. But that was 20 years ago.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list