为什么Go不支持函数和运算的重载

原创
2016/05/27 10:50
阅读数 1.2K
AI总结

 

Method dispatch is simplified if it doesn't need to do type matching as well.

不需要做类型匹配的方法处理是简单的。

Experience with other languages told us that having a variety of methods with the same name but different signatures was occasionally useful but that it could also be confusing and fragile in practice.

其他语言的经验告诉我们,函数名称相同,而参数不同,这种使用场景只是偶尔。但是在实践中,重载的应用是很容易令人困惑。

Matching only by name and requiring consistency in the types was a major simplifying decision in Go's type system.

在Go语言里面,函数名称的唯一性规定是为了让程序看起来简洁明了。

Regarding operator overloading, it seems more a convenience than an absolute requirement. Again, things are simpler without it.

关于运算的重载,它也不是必须不可的。同上,没有运算符的重载,程序看起来更简洁明了。

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
AI总结
返回顶部
顶部