Skip to content

proposal: Go 2: String interpolation #55894

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

Closed
xbt573 opened this issue Sep 27, 2022 · 1 comment
Closed

proposal: Go 2: String interpolation #55894

xbt573 opened this issue Sep 27, 2022 · 1 comment

Comments

@xbt573
Copy link

xbt573 commented Sep 27, 2022

Author background

  • Would you consider yourself a novice, intermediate, or experienced Go programmer?
    Something between novice and intermediate
  • What other languages do you have experience with?
    C#, Python, JS/TS

Related proposals

Proposal

  • What is the proposed change?
    This proposal adds way to interpolate values to string other than fmt.Printf, concatenation, or others
  • Who does this proposal help, and why?
    This proposal helps to make interpolation simple and don't remember all %something in fmt.Printf
  • Please describe as precisely as possible the change to the language.
    This interpolation use strings, prefixed by hash (#) symbol, they converted to normal strings at runtime, because expressions can vary
  • What would change in the language spec?
    Specification will include information about syntax of this string interpolation
  • Is this change backward compatible?
    Yes
  • Show example code before and after the change.
  • Before
a := 5
hash := "#"

// Simple output
fmt.Printf("%v\n", a)

// Pad char
fmt.Printf("%-3v\n", hash)
  • After
a := 5
hash := "#"

// You can even not import fmt!
// Simple output
println(#"{a}")

// Pad char (shows optional formatting)
println(#"{[%-3v] hash}")
  • Orthogonality: how does this change interact or overlap with existing features?
    This is new feature
  • Is the goal of this change a performance improvement?
    No

Costs

  • Would this change make Go easier or harder to learn, and why?
    It's makes interpolation in Go easier to learn because of simple syntax
  • What is the cost of this proposal? (Every language change has a cost).
    Implementation of this interpolation
  • How many tools (such as vet, gopls, gofmt, goimports, etc.) would be affected?
    gopls, vet
  • What is the compile time cost?
    Zero
  • What is the run time cost?
    Additional interpolation
  • Can you describe a possible implementation?
    No
  • Do you have a prototype? (This is not required.)
    No
@gopherbot gopherbot added this to the Proposal milestone Sep 27, 2022
@ianlancetaylor
Copy link
Member

Thanks. Closing as dup of #34174 and #50554.

@golang golang locked and limited conversation to collaborators Sep 27, 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

3 participants