Fluent StringBuilder in Go

Ishan Jain
1 min readJul 31, 2018

--

GoLang’s strings.builder was not was I was expecting coming from a Java world. Reason being, I was used to the “fluent” nature of StringBuilder’s Java API. A typical Java code for joining different variables using StringBuilder looks like:

Yes, there are other “cleaner” ways of doing this specifically but thats not the point.
Lets look at the equivalent crude Go code.

Let’s say you do not care about errors, the code still looks something like:

It still is a lot verbose for my taste (someone coming from Java world is saying this, oh the irony!). Lets make fluent StringBuilder in go.

Looks a lot cleaner to me, although we are ignoring the error returned from WriteString.

--

--