Docs: Section on local variables
bearophile
bearophileHUGS at lycos.com
Fri Apr 20 12:37:25 PDT 2012
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
More information about the Digitalmars-d
mailing list