Hi, could we add new methods to solve the problem of cutset type in Strings.{Trim/TrimRight/TrimLeft}.
Apparently, many gohpers misunderstood the this cutset type, and it cauese some bugs. And, there're several proposals for solving the cutset type problem:
I read through this proposals and see the conclusion is no change will be made.
This cutset problem affects many developers:
if we have known the problem already, we may not make the same mistake again.
but if we doesn't know it in advance, we may likely make the mistake.
In python, str.{strip/rstrip/lstrip}('cutset') method works the same as in go strings.{Trim/TrimRight/TrimLeft}(s, "cutset"). Maybe this signature is ok.
If we:
add new methods strings.{TrimCutset\TrimRightCutset\TrimLeftCutset}, and add //Deprecated and go:linkname on strings.{Trim/TrimRight/TrimLeft}, we may make this clearer
or add new methods strings.{TrimCutset\TrimRightCutset\TrimLeftCutset}, and declare the cutset as []rune, and use this methods to reimplement strings.{Trim/TrimRight/TrimLeft}
The text was updated successfully, but these errors were encountered:
hitzhangjie
changed the title
proposal: strings.{Trim/TrimRight/TrimLeft} change cutset type from string []rune
proposal: add new methods strings.{Strip/StripRight/StripLeft} to deprecate strings.{Trim/TrimRight/TrimLeft} to define cutset as []rune
Dec 31, 2021
hitzhangjie
changed the title
proposal: add new methods strings.{Strip/StripRight/StripLeft} to deprecate strings.{Trim/TrimRight/TrimLeft} to define cutset as []rune
proposal: add new methods to deprecate or reimplement strings.{Trim/TrimRight/TrimLeft} to define cutset as []rune
Dec 31, 2021
hitzhangjie
changed the title
proposal: add new methods to deprecate or reimplement strings.{Trim/TrimRight/TrimLeft} to define cutset as []rune
proposal: add new methods to deprecate or reimplement strings.{Trim/TrimRight/TrimLeft} to avoid mistakes
Dec 31, 2021
I dont see how using []rune will avoid the duplicate characters in cutset issues as the user now may as well define duplicate elements in []rune. In addition []rune has the downside of not being a 1 to 1 replacement of the old function signature and has larger storage requirements and is not constant.
I dont think Strip conveys a meaning that it is a cutset more or less then Trim so I dont think just advising to use Strip instead of Trim makes developers more or less likely to mistake the function as not using a cutset.
@martisch I edit the issue again to focus on 1 suggestion. Thanks.
ianlancetaylor
changed the title
proposal: add new methods to deprecate or reimplement strings.{Trim/TrimRight/TrimLeft} to avoid mistakes
proposal: strings: add new functions to deprecate strings.{Trim/TrimRight/TrimLeft} to avoid mistakes
Dec 31, 2021
Hi, could we add new methods to solve the problem of
cutset
type in Strings.{Trim/TrimRight/TrimLeft}.Apparently, many gohpers misunderstood the this
cutset
type, and it cauese some bugs. And, there're several proposals for solving thecutset
type problem:I read through this proposals and see the conclusion is no change will be made.
This
cutset
problem affects many developers:In python,
str.{strip/rstrip/lstrip}('cutset')
method works the same as in gostrings.{Trim/TrimRight/TrimLeft}(s, "cutset")
. Maybe this signature is ok.If we:
//Deprecated
andgo:linkname
on strings.{Trim/TrimRight/TrimLeft}, we may make this clearercutset
as []rune, and use this methods to reimplement strings.{Trim/TrimRight/TrimLeft}The text was updated successfully, but these errors were encountered: