On Nov 12, 5:54 pm, Gherald <
gher...@gmail.com> wrote:
>
> Sure there are purposeful reasons, the variable may be useful at a latter
> point. In this case you might go through several revisions of coding the
> inner loop, some which use the variable and some which don't.
>
> Requiring its name altered to _ or the declaration commented out may be
> useless make-work that only slows development.
>
> If it doesn't break but _might_ be inadvertent then it should produce a
> warning, not an error.
>
> Ditto for things that _might_ be mistakes, e.g. gri's mention of := instead
> of =
>
> Resolution ought to be a requirement for commits, not compilation.
I completely agree that there are situations where you may or may not
know whether or not a value will be needed (especially since many of
us are still just learning of this really cool new language). In those
cases, the solution for rapid testing of various scenarios is obvious:
use the variable. In other words, define some function that takes in
an 'interface{}' parameter, no return values, and has an empty body.
Then, call that function once for each variable you aren't sure about.
This way, you can ignore the variables you are "trying out", with code
that effectively does nothing except prevent the error.
All of that being said, though, I am a strong believer in designing
before writing. So, I probably wouldn't use what I just posted, and I
really hope is doesn't taint go code all of the internet. Go is a new
language, and with that comes new ways of thinking. I find myself
erasing entire blocks of code that just don't make sense with the
mechanisms provided by the language. So, before you try to turn Go
into a glorified C++/Java compiler, try to understand why decisions
were made in the language, and the reasoning behind them.
=)