OK we already have the answer that StringBuilder
should be used to concatenate strings in go
:
How to efficiently concatenate strings in Go?
Now, I am reviewing a PR. There is this code:
const CustomerID [32]byte
const paymentPrefix = "payment_done_"
const sentPrefix = "invoice_sent_"
const receivedPrefix = "invoice_received_"


func paymentKey(customer CustomerID) string {
 return paymentPrefix + customer.String()
}
// same for the other two Key
I am wondering if I should request to use StringBuilder
here
func paymentKey(customer CustomerID) string {
var str string.Builder
str.WriteString(paymentPrefix)
str.Write(customer)
return str.String()
}
It is a 32 byte ID which first needs to be converted to string
and then concatenated with +
These are only two strings but potentially called a lot, that is why I think it is justified to question concatenation.