All of this could've been prevented if Go just had two ways to compile. Debug and release.
The go devs decided against this since they didn't want to build a highly optimizing (read: slow) compiler, but that is missing the point of developer ergonomics.
It could be prevented in an even simpler way: emitting warnings.
Most people nowadays ban building with warnings in CI and allow them during local development. But “CI” was barely a thing when go was developed so they just banned them completely. And now they are probably too stubborn to change.
The Go decision was explicitly to not have warnings, and the unused identifier thing complained about is merely a consequence of that.
https://go.dev/doc/faq#unused_variables_and_imports
As an outsider to Go, it feels to me like this basic pattern comes up over and over again in Go:
Q. Why can’t I have feature X?
A. We thought of that already, and your opinion is wrong.
Q. But basically every other language in existence supports this. And it makes development easier. We would really, really like it. Please?
A. Apparently you don’t get it. Here’s a pointer to a 15 year-old post on a mailing list where the first time someone asked for this, we said no. Your opinion is wrong.
> And now they are probably too stubborn to change.
Sounds like we agree!