debugging - Go语言中常见的陷阱有哪些?

标签 debugging go anti-patterns

<分区>

我打算在 Golang 上做一些程序分析,就像 pylint ,试图从源代码中查找问题。所以我要问的第一个问题是:

What are the common pitfalls specialized in the Go language?

我知道 Python 中有一些,例如数组变量 '[]' 作为参数,可变对象与不可变对象(immutable对象)。 (查看更多 herethere )。

示例 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),但无法获得典型的。能否请您提供一些示例,例如内存泄漏、并发、意外结果和误解。

最佳答案

Golint是 Go 源代码的 linter。

关于debugging - Go语言中常见的陷阱有哪些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21297386/

相关文章:

性能反模式

node.js - 使用 --inspect-brk 选项时 WebSockets 请求是预期错误

visual-studio - Visual Studio 的 "Start Without Debugging"在 JetBrains Rider 中是否等效?

c# - Visual Studio 在出现异常时退出调试

c++ - this.attribute 应该是 this->attribute 是什么意思

pointers - 为什么指向int的指针是使用 “*int”而不是 “&int”初始化的?

go - 用 Helm 压平字典

go - 奇怪的错误消息: mismatched types rune and string

c# - 避免使用 DataContractSerializer 和继承重复自己 (DRY)

javascript - Nightmare Promises with for..loop api calls, waterfall & anti-pattern (Bluebird.js)