<分区>
我打算在 Golang 上做一些程序分析,就像 pylint ,试图从源代码中查找问题。所以我要问的第一个问题是:
What are the common pitfalls specialized in the Go language?
我知道 Python 中有一些,例如数组变量 '[]' 作为参数,可变对象与不可变对象(immutable对象)。 (查看更多 here 和 there )。
示例 1:
>>> def spam(eggs=[]):
... eggs.append("spam")
... return eggs
...
>>> spam()
['spam']
>>> spam()
['spam', 'spam']
>>> spam()
['spam', 'spam', 'spam']
>>> spam()
['spam', 'spam', 'spam', 'spam']
示例 2:
Map<Person, String> map = ...
Person p = new Person();
map.put(p, "Hey, there!");
p.setName("Daniel");
map.get(p); // => null
所以我真正想知道的是Golang中类似的。我已经在网上搜索但找不到它。我还查看了一些 git 存储库历史记录(例如 docker.io),但无法获得典型的。能否请您提供一些示例,例如内存泄漏、并发、意外结果和误解。