在Go语言中缺少了C++所具有的什么特性?

huangapple go评论83阅读模式
英文:

What is absent in go that C++ has?

问题

Go语言旨在成为一种简单的语言,大约有25个关键字。因为它很简单,我想知道与其他语言(如C++或C#,在我看来比C++更复杂)相比,它有什么不同。

我理解它之所以简单是因为它有较少的关键字和其他东西,但我不了解这门语言,所以它为了这个决定而做出了什么妥协或放弃了什么?

英文:

Go is meant to be a simple language and there is about 25keywords. Because it is simple i was wondering what does it not have compared to other language like C++ or C# (which IMO is more complex than C++)

I understand its simple bc it has less keywords and other things but i dont know the langauge so what did it have to tradeoff or leave out because of that decision?

答案1

得分: 3

正如其他人所评论的,关键字的数量并不是衡量简单性的指标,但你是对的,Go确实很简单。我不了解C#,但以下是一些Go中没有的一些基本C++特性:

  • 泛型(模板)。关于如何在Go中支持泛型已经进行了很长时间的讨论。它们可能会在未来的某个时候出现,但现在还没有。
  • 继承。Go的类型模型不像那样工作。这意味着没有重载,没有受保护的字段,没有多态等。
  • 异常处理。Panic和recover可以实现类似的功能,但它不是异常处理。
  • 构造函数和析构函数。类型只有初始值,仅此而已。
  • C宏

我可能漏掉了一些东西。

编辑:我忘记了指针算术

英文:

As others commented, number of keywords is not a metric for simplicity, but you're right that Go is simple. I don't know C#, but here are some essential C++ features not available in Go:

  • Generics (templates). There's been a long discussion about how to have support for generics in Go. They may come someday, but not yet.
  • Inheritance. Go's typing model just doesn't work like that. That means there's no overloading, no protected fields, no polymorphism, etc.
  • Exception handling. Panic and recover covers that, but it's not exception handling.
  • Constructors and destructors. Types have initial values and that's all.
  • C macros.

I may be missing something.

EDIT: I missed pointer arithmetic‌​.

huangapple
  • 本文由 发表于 2012年5月3日 15:15:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/10426797.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定