On Tuesday, February 19, 2013 1:34:04 PM UTC-8, Johann Höchtl wrote:
On 02/19/2013 10:31 PM, Kamil Kisiel wrote:
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:>>
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
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

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
The compiler shouldn't give an error about the inner found, as a value
gets assigned to, but about the outer, which gets declared but is never
explicitly assigned to.
I don't see what's wrong with that, the behaviour is explicitly defined in
the spec, the variable is initialized to the zero
value: http://golang.org/ref/spec#Program_initialization_and_execution

var found bool

is simply equivalent to

var found bool = false

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