On Tuesday, February 19, 2013 12:50:22 PM UTC-8, Johann Höchtl wrote:
On 02/19/2013 09:39 PM, Rémy Oudompheng wrote:
On 2013/2/19 Johann Höchtl <johann....@gmail.com <javascript:>> wrote:

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

result := Function()

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"

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.
But that's exactly the way I would want, and expect it to work. I don't see
why the compiler should produce an error here. Sure it's possible to do it
by accident, but there are many cases where you can make intentional use of
such constructs, such as limiting the scope of an err variable.

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


Follow ups

Related Discussions



site design / logo © 2021 Grokbase