Avatar ·

How to get rid of the "declared and not used" error in Go?

Hello everyone! I recently started learning Go, and one error keeps annoying me. I write simple code, for example:\n\n```go\npackage main\n\nimport "fmt"\n\nfunc main() {\n result := calculateSum(5, 7)\n fmt.Println("Hello, world!")\n}\n\nfunc calculateSum(a, b int) int {\n sum := a + b\n return sum\n}\n```\n\nAnd I get: `result declared but not used`. Okay, I removed the assignment:\n\n```go\ncalculateSum(5, 7)\n```\n\nBut now the error: `calculateSum declared but not used` — even though I'm calling it! What if I just want to test a function without using the result? Or when I'm writing code quickly and don't yet know where to put the variable?\n\nIt's especially annoying when I declare a variable for future use, and the compiler complains, forcing me to write `_ = result`. This feels like a crutch...