gah! I hate the new string syntax

Amit Patel amitp at Xenon.Stanford.EDU
Sat Mar 10 20:53:56 EST 2001


 Alex Martelli <aleaxit at yahoo.com> wrote:
| "Amit Patel" <amitp at Xenon.Stanford.EDU> wrote in message
| news:97soak$qh9$1 at nntp.Stanford.EDU...
|     [snip]
| > When I see split(a,b), I think, "Oh, this isn't an inherent part of a
| > string-- *I* could write it, even though I didn't write the string
| > object."
| >
| > When I see b.split(a), I think, "This is a basic part of a string, and
| > I *cannot* write it."
| 
| Reasonable, but the latest assertion is a bit too strong -- tone down
| to "cannot write it without typeswitching or other potential inefficiencies
| since it doesn't do a general dispatch on b".

What I mean to say is that I cannot write new methods on strings.  So
my function mysplit(a,b) is written mysplit(a,b), because I am not
Guido.  But if I were Guido, then I could just declare that mysplit is
now a method on string objects, and we'd write b.mysplit(a).  So the
syntax that everyone has to use depends on who wrote mysplit and who
has control over the string class.  Since I don't control the string
class, I have to use a different syntax than someone who does have
control over the string class gets to use.  That seems okay if the
function is some essential part of that class.  But it seems "wrong"
if the function is there merely for convenience.

   - Amit





-- 
--
Amit J Patel, Computer Science Department, Stanford University
http://www-cs-students.stanford.edu/~amitp/



More information about the Python-list mailing list