On 02/19/2013 10:03 PM, Jan Mercl wrote:
On Tue, Feb 19, 2013 at 9:50 PM, Johann Höchtl wrote:

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.

This is how block scoping must work for it to be useful. Imagine for
example code getting moved around. There's no reason for the compiler to
say anything about it.
Ok, but when you remove the block, code like this is very likely to be

var i int

if i != 0 {
} else {

Of course, Go promises to be well defined but it's still likely to make
no sense as i get's never explicitly assigned to.

Dr. Johann Höchtl

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