Jonathan M Davis:

Local Variables
It is an error to use a local variable without first assigning it a value.
...
There's no way that this is ever going to be the case. There are cases where
you can't use a variable's initial value. For example,

T var;
if(cond)
{
 //do a bunch of stuff
 var = something;
}
else
 vare = somethingElse;

I think "use a local variable" doesn't mean "assign it immediately", it means essentially "reading it before writing it". So that code is correct.


This could done, but it's definitely _not_ a warning or error right now. It's also not ever going to be an error AFAIK, so I'd definitely vote to remove it from the docs.

I think in Go unused local variables are an error.
If you go here and you try to add "x := 1" inside the main you receive an error, not a warning:
http://golang.org/#
And I think today Go programmers survive well enough to such strictness.

Bye,
bearophile

Reply via email to