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

Already on GitHub? Sign in to your account

fmt: pp should implement WriteString() #20786

pierrre opened this Issue Jun 24, 2017 · 9 comments


None yet
6 participants

pierrre commented Jun 24, 2017

What version of Go are you using (go version)?


What did you do?

In my code, I'm implementing fmt.Formatter.
In order to write a string to the fmt.State, I'm calling io.WriteString().
I know that this function has an optimization that allows to call WriteString() if w implements it.
Sadly, in my case the "real" type of fmt.State is fmt.pp.
fmt.pp only has Write().

What did you expect to see?

I think we should add:

func (p *pp) WriteString(s string) (ret int, err error) {
	return len(s), nil

in my case, it greatly improve performance and reduces memory allocation.
We could also implement WriteByte() and WriteRune(), since fmt.buffer has these methods.

@bradfitz bradfitz added this to the Go1.10 milestone Jun 24, 2017


bradfitz commented Jun 24, 2017

Sounds reasonable.

@bradfitz bradfitz added the HelpWanted label Jun 24, 2017

nikhita commented Jun 25, 2017

I want to contribute to Go and noticed the Help Wanted label. If no one is working on it, I'd like to take it! :)


martisch commented Jun 25, 2017

io.WriteString() uses a runtime check so it looks like it should work without changing the State Interface definition. For go2 we could then think about wether it makes sense to update the State Interface.

@nikhita go ahead if you want too. Please add r@golang.org and moehrmann@google.com as reviewers. We can review before go1.10 but we can only submit when the code tree opens for go1.10 start of August.

nikhita commented Jun 25, 2017

@martisch will do that, thank you.


martisch commented Jul 10, 2017

did you have time to start your first CL for go?
Any blockers encountered that we can help with?

nikhita commented Jul 10, 2017

sorry, was busy at work - didn't have time to work on it.
But will try working on it on my flight to GopherCon now. :)
Maybe I can even ask any questions I have during the Go contributor workshop at GopherCon? :)


martisch commented Jul 10, 2017

no problem. Asking at the contributor workshop sounds good.

CL https://golang.org/cl/48871 mentions this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment