I wish Go has string interpolation 😮‍💨
Is there a variant of `fmt.Sprint` that doesn't add spaces between operands?
PS: I hate `fmt.Sprintf`
#go #golang
Go Playground - The Go Programming Language

@Merovius ugh, seems I misread the examples in the standard docs. Thanks for pointing out.
Now I'm confused on what's the meaning of “Spaces are added between operands when neither is a string.” 🤔

@drsensor Oh, "fun". This demonstrates: https://go.dev/play/p/NdoiBDbQuzn

TBH I never use Sprint with more than one argument, so I wasn't really aware either.

Go Playground - The Go Programming Language

@Merovius oh no, I began to hate Go https://go.dev/play/p/h5mjpM3qJB1
seriously, what's the purpose of Sprint 😂
Go Playground - The Go Programming Language

@drsensor @Merovius fmt.Sprint() and fmt.Sprintf() are very different beasts.

Only fmt.Sprint() does the "spaces" added thing. The idea being that if you go:

a := 1
b := 2
fmt.Sprint(a, b)

conveniently assumes you want to see:

1 2

rather than

12

If you go:

fmt.Sprint(a, " gt ", b)

Sprint() assumes you've considered spacing and prints:

1 gt 2

fmt.Sprint() is purely a convenience function which mostly "does what you want". If you don't like it, use the myriad prescriptive functions.

@markd @Merovius at first I assume Sprint always add spaces, but no, it only add spaces at certain condition. Due to this weird behaviour, I'm wondering if there is an example when it's convenient to use Sprint instead of others 🤔

@drsensor @Merovius I see Sprint() as more of a diagnostic/debug output service.

a := 1
b := 2
Sprint(a, b)

is less keystrokes and less thinking than

Sprintf("%d %d", a, b)

as is:

Sprint(a, " < ", b)

vs
Sprintf("%d < %d", a, b)

In general, as a diagnostic print, you can just feed arguments to Sprint() and you'll get good output without worrying about formatting, e.g:

Sprint(int, string, []byte, float, struct)

just works.

So yeah, convenient. Just not a strict formatting tool.