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
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.
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.
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
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.
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.
erroneous:
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.
-j
--
Dr. Johann Höchtl
http://www.facebook.com/myprivate42
https://plus.google.com/109572797756514902540
--
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.