FAQ

On 02/19/2013 09:39 PM, Rémy Oudompheng wrote:
On 2013/2/19 Johann Höchtl wrote:

Bumping, as I consider it a sane proposal
It seems ridiculously strict to forbid people from writing:

result := Function()
DoSomethingWith(result)

It looks like perfectly valid code and I wouldn't want to litter it
with "_ := &result".
You should rather use a govet-like tool to detect shadowing and filter
out those you don't like.
Sure, but in this case no shadowing happens. But take a look at this case:

var found bool
for idx := range []int{1, 3, 5} {
if found := answertoeverything(idx); found == true {
answer = "We got an answer"
break
}
}

if found {
fmt.Println("The answer is", answer)
} else {
fmt.Println("No answer was found")
}

The outer found get's never explicitly assigned to, yet it's legal and
sane code because of the default initialization promise. However, would
the compiler bark, the shadowing would become obvious.
Rémy.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2021 Grokbase