Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: bytes, strings: TrimStart and TrimEnd replacing TrimLeft and TrimRight #54678

Closed
hajimehoshi opened this issue Aug 25, 2022 · 6 comments

Comments

@hajimehoshi
Copy link
Member

hajimehoshi commented Aug 25, 2022

TrimLeft and TrimRight implicitly assumes a left-to-right writing system, but this is odd. Actually a string literal can include right-to-left languages and how to show them depends on editors. We don't have to (or cannot) determine visible directions of texts.

So, what about adding new functions TrimStart and TrimEnd as aliases to TrimLeft and TrimRight, and deprecating TrimLeft and TrimRight? This naming is the same way as CSS (e.g. padding-inline-start for padding-left)

The replacing targets are:

  • bytes.TrimLeft
  • bytes.TrimLeftFunc
  • bytes.TrimRight
  • bytes.TrimRightFunc
  • strings.TrimLeft
  • strings.TrimLeftFunc
  • strings.TrimRight
  • strings.TrimRightFunc
@gopherbot gopherbot added this to the Proposal milestone Aug 25, 2022
@hajimehoshi hajimehoshi changed the title proposal: strings: TrimStart and TrimEnd replacing TrimLeft and TrimRight proposal: bytes, strings: TrimStart and TrimEnd replacing TrimLeft and TrimRight Aug 25, 2022
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Aug 25, 2022
@shmsr
Copy link
Contributor

shmsr commented Aug 26, 2022

Yes, I agree. It'd be similar to Rust, i.e., trim_left has been deprecated since 1.33.0, and it is recommended to use trim_start instead.

https://doc.rust-lang.org/std/string/struct.String.html#method.trim_left

@rsc
Copy link
Contributor

rsc commented Sep 28, 2022

This seems like a lot of churn for not too much benefit.
Deprecating old names creates IDE prompts and takes up developer time.
The bigger problem with these functions is that people think TrimLeft is TrimPrefix, and calling it TrimStart will not make that problem go away. It might make the problem worse.

@rsc rsc moved this from Incoming to Active in Proposals Sep 28, 2022
@rsc
Copy link
Contributor

rsc commented Sep 28, 2022

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc
Copy link
Contributor

rsc commented Oct 6, 2022

Based on the discussion above, this proposal seems like a likely decline.
— rsc for the proposal review group

@rsc rsc moved this from Active to Likely Decline in Proposals Oct 6, 2022
@itchyny
Copy link
Contributor

itchyny commented Oct 6, 2022

The bigger problem with these functions is that people think TrimLeft is TrimPrefix, and calling it TrimStart will not make that problem go away. It might make the problem worse.

I agree that it still causes confusion between Prefix and Start. But how about adding Any suffix to the functions with cutset argument?

substr cutset func
Contains ContainsAny #54386
Index IndexAny IndexFunc
LastIndex LastIndexAny LastIndexFunc
TrimPrefix TrimLeftTrimPrefixAny TrimLeftFuncTrimPrefixFunc
TrimSuffix TrimRightTrimSuffixAny TrimRightFuncTrimSuffixFunc

@rsc
Copy link
Contributor

rsc commented Oct 12, 2022

No change in consensus, so declined.
— rsc for the proposal review group

@rsc rsc moved this from Likely Decline to Declined in Proposals Oct 12, 2022
@rsc rsc closed this as completed Oct 12, 2022
@golang golang locked and limited conversation to collaborators Oct 12, 2023
@rsc rsc removed this from Proposals Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants