Why isn't short variable declaration allowed at package level in Go?

Trevor Dixon :

This is allowed:

package main

var a = 3

...

But this isn't:

package main

a := 3

...

Why not? Why couldn't short variable declaration outside a function be treated regular declaration without a type? Just to simplify parsing?

Gustavo Niemeyer :

According to Ian Lance Taylor in this thread shortly after the public announcement:

At the top level, every declaration begins with a keyword. This simplifies parsing.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why there is a package declaration in Go?

Why is variable declaration not allowed here?

Why is variable declaration not allowed as a parameter, but function declaration is?

Why method isn't allowed?

Difference between "variable declaration" and "short variable declaration" at local scope in Go

Why is ;; allowed after a local variable declaration, but not after a field declaration?

Why this constant declaration isn't working in Java?

Why isn't a lambda allowed in a template instantiation?

Why isn't ReadWriteLock upgrade allowed?

Why isn't 〉allowed as a Haskell infix operator?

Why isn't this pointer arithmetic allowed in C?

Why isn't fallthrough allowed in a type switch?

Why isn't this allowed before super()

Short declaration in Go

Why isn't a qualified static final variable allowed in a static initialization block?

Java variable declaration not allowed

variable declaration not allowed here

Why is declaring a variable in switch statement allowed? but not declaration + initialization?

Why isn't there a useful JBoss package?

Why isn't this package auto-updating?

Why isn't launchpad building my package?

Why package Share flutter isn't defined?

In Haskell why does the GHCi cmd line allow me to change the value of a variable, which isn't allowed when loading from a text file

Why isn't this method promoted in Go?

Why isn't my Go Reader working?

Why isn't python optimising the function declaration out of the loop?

When the declaration of the function is in a traditional style, why isn't the output correct?

TradingView's Pinescript - why isn't recursion allowed?

Why isn't overloading with a different generic type as a parameter allowed?