Hi everyone,
I come from a mostly JavaScript and .NET background and am currently transitioning to Golang. I’m really liking the language and ecosystem so far but one thing that has irked me a little is that I can’t leave variables as placeholders or even for debugging.
var placeholder1 [][]string
var test1 string
Something as simple as the above results in two compiler errors stating that the variables are declared but not used
`.
A bit of Googling showed quite a few people with similar complaints, but there was one solution that seemed to fit my use-case pretty well:
var placeholder1 [][]string
var test1 string
// Use discards
_, _ = placeholder1, test1
By simply using a discard the compilation error can be circumvented. There’s a fairly detailed discussion on Stackoverflow: https://stackoverflow.com/a/62951339/522859
Leave a Reply