为什么Go没有在包级别允许使用短变量声明? [英] Why isn't short variable declaration allowed at package level in Go?
本文介绍了为什么Go没有在包级别允许使用短变量声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
推荐答案
据Ian Lance Taylor在此线程在公开发布后不久: $ b
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.
这篇关于为什么Go没有在包级别允许使用短变量声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文