FAQ
This is more about the fact that code becomes much less portable, and can
later become invalid because of a top level import:

func a() {
math := "is hard"
fmt.Println(math)
}

If you later import "math" into this file, this function suddenly becomes
invalid if you can't shadow. Since anyone can name imports whatever they
want, this could be a huge pain (yes you could rename the import).



On Thursday, February 21, 2013 9:09:52 AM UTC-5, Patrick Mylund Nielsen
wrote:
A "var oa int" would still be in block scope.


On Thu, Feb 21, 2013 at 2:58 PM, Jan Mercl <0xj...@gmail.com <javascript:>
wrote:
On Thu, Feb 21, 2013 at 2:38 PM, Patrick Mylund Nielsen
<pat...@patrickmylund.com <javascript:>> wrote:
I would propose another radical solution for this: Simply that
shadowing
variables is not allowed.
Good bye block scoping.
Block scoping does not disappear if you can't declare new variables with
names identical to variables in outer scopes.
package main
var a int
func main() {
var a int // main.go:4: a redeclared in this block previous
declaration at main.go:2

...
}

Well, is it just me who doesn't call the above 'block scoping' anymore?

-j
--
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