Re: Why don't stringobjects have methods?

Donald Beaudry (don@vicorp.com)
Mon, 4 Apr 94 15:17:43 EDT

[ stuff about using 'is' to compare strings ]

I have been thinking about this issue a bit since I started using
Python. But I don't think that making all strings unique as you
described is the right answer. Instead I would rather see a new
string type introduced to the language. I would call it a 'symbol'
(as in lisp) and it would have the semantics that you described.

There are too many places in the python source where strcmp() is
called but a simple pointer comparison would do just as well if only
you could be guaranteed that all 'symbols' that look the same are the
same.

A good example of this is in the GetAttr() method of any object. When
the interpreter calls this method, is has a string object to start
with. The address of the text is extracted and passed to the
GetAttr() method. This method then proceeds to compare this string to
the many strings in the objects method table... one call to strcmp()
for each method until the method is found. Given the existance of a
global symbol table, each method name in the objects method table
could be replaced by the symbol object of the same name. Then the
comparison could be done by pointer without the overhead of a function
call. This gets really nasty if you keep your method or attribute
information in a dictionary. Because then you need to create a string
object that can be passed as a key to the dictionary lookup function.

I think that this relatively minor enhancement and a few other
associated changes would greatly increase the speed with which Python
resolves method and attribute names. By passing this feature on to
the Python user, it gives them the ability to do symbolic processing
much more quickly.

--Don

______ ______
\_\_\_\ /#/#/#/
\_\_\_\ ______
\_\_\_V#/#/#/ Donald Beaudry don@vicorp.com
\_\_/#/#/#/ V. I. Corporation uunet!vicorp!don
\_/#/#/#/ 47 Pleasant Street PHONE: (413) 586-4144
V#/#/#/ Northampton, MA 01060 FAX: (413) 586-3805