[Python-ideas] New explicit methods to trim strings
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
> >>> a == c - b
> >>> b = -a + c
> # Just like numbers except.
> >>> a + b == b + a
> 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.
> 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.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas