[Python-ideas] Experiment: Adding "re" to string objects.

Sean Reifschneider jafo at tummy.com
Tue Jul 21 22:32:17 CEST 2009


On 07/20/2009 05:52 PM, Steven D'Aprano wrote:
> there's a far more critical flaw in the above idiom: it operates by 
> side-effect in an unsafe way.

But this is hardly unprecedented.

   def f(arg): arg.append('world')
   l = []
   f(l)
   l.append('hello')
   l[0] == 'hello'

The difference being that strings are immutable and lists are not, but I
don't see a particular concern with string.re being mutable, while still
keeping strings immutable.  If you call a function with side-effects, it's
going to result in side-effects.  That's the nature of the beast, and just
a part of programming.

But, I agree that it would be ideal if we could prevent this in most cases.
Do you have an idea about how to prevent this?

> Why is this not mutable?

I understand that the string.re is mutable, but saying that this "makes
strings mutable" is kind of misleading...

> Hang around comp.lang.python for long enough, and you too will get a 
> very jaundiced view of regexes being misused, usually by people who 
> have come from a Perl background.

Don't take this the wrong way, but...  Why do we care?  There will always
be people who misuse things.  If they are more familiar with using an re
than "endswith", we can certainly educate them when they are looking for
it, but...

Why should we penalize people who are not abusing regular expressions just
because some people might?

> Perhaps that, and the obvious multisearch() function, should be added to 
> the re module.

Agreed.

Sean
-- 
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090721/709b26e2/attachment.pgp>


More information about the Python-ideas mailing list