# [Python-ideas] New explicit methods to trim strings

Anders Hovmöller boxed at killingar.net
Mon Mar 25 08:24:47 EDT 2019

```I think this is a terrible idea. I also think it's a mistake that python uses + for string concatenation and * for string repeat. You end up with type errors far from the first place you could have had the crash! That ship has obviously sailed buy we shouldn't make even more mistakes in the same vain because we have some Stockholm syndrome with the current state of the language, or for a misplaced ideal of consistency.

> On 25 Mar 2019, at 11:22, Jonathan Fine <jfine2358 at gmail.com> wrote:
>
> Instead of naming these operations, we could use '+' and '-', with semantics:
>
>     # Set the values of the variables.
>     >>> a = 'hello '
>     >>> b = 'world'
>     >>> c = 'hello world'
>
>     # Some values between the variables.
>     >>> a + b == c
>     True
>     >>> a == c - b
>     True
>     >>> b = -a + c
>     True
>
>    # Just like numbers except.
>     >>> a + b == b + a
>     False
>
> This approach has both attractions and problems. And also decisions. The main issue, I think come to this. Suppose we have
>      a, A = ('a', -'a')
>      b, B = ('b', -'b')
>      a + A == A + a  == ''
>      b + B == B + b == ''
>      A + '' == '' + A == A
>      B + '' == '' + B == B
> together with unrestricted addition of a, A, b, B then we have what mathematicians call the free group on 2 letters, which is an enormous object. If you want the math, look at, https://en.wikipedia.org/wiki/Free_group#Examples
>
> We've made a big mistake, I think, if we allow Python programmers to accidentally encounter this free group. One way to look at this, is that we want to cut the free group down to a useful size. One way is
>    >>> 'hello ' - 'world' == 'hello'   # I like to call this truncation.
>    True
> Another way is
>     >>> 'hello' - 'world'  # I like to call this subtraction.
>    ValueError: string s1 does not end with s2, so can't be subtracted
>
> I hope this little discussion helps with naming things. I think this is enough for now.
>
> --
> Jonathan
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190325/a839a045/attachment-0001.html>
```