Go-Scala-Go!主要有哪些区别?

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

Go-Scala-Go! What are the main differences?

问题

我刚刚发现了这个网页,比较了一些用Scala、C#和Go编写的代码。我很惊讶地发现,Scala和Go的代码看起来非常相似,比Scala和C#的代码更相似。

所以我的问题是:Scala和Go之间最显著的区别是什么?

英文:

I just found this web page comparing some code written in Scala, C# and Go. I am astonished to see how close Scala and Go code looks like, much more than Scala code compared to C# code.

So my question is: What are the most significant differences between Scala and Go?

答案1

得分: 26

老实说,那段Scala代码以一种非常命令式的风格编写。我不是一个纯粹的函数式主义者,但是将该页面的埃拉托斯特尼筛选法代码与Stream类的开始处更短、更易读的埃拉托斯特尼筛选法示例进行对比。该页面的代码中有大量的变量和while循环,更不用说各种地方的位移操作了。现在,我不知道有多少人对什么被认为是符合惯用的Scala代码达成共识,但这绝对不是其中之一。因此,除了它们都是C的后代之外,它并没有说明Scala和Go之间的相似之处。

英文:

Honestly, that Scala code is written in an extremely imperative style. I'm no functional purist, but contrast that page's Sieve of Eratosthenes code with the much shorter, more legible Sieve of Eratosthenes example at the beginning of the Scaladoc for the Stream class. That page's code has got loads of vars and while-loops, not to mention bitshifts, all over the place. Now, I don't know how much of a consensus there is about what's considered idiomatic Scala code, but this is most definitely nowhere near it. As such, it doesn't say anything about the similarity between Scala and Go other than the fact that they're both descendants of C.

答案2

得分: 14

我不这么认为,至少在概念上它们非常不同。Go更像C++,面向"低级",而C#只有一些函数式特性,而Scala允许你编写典型的"函数式"代码(比OCaml或Haskell更冗长,但类似)。Scala的类型系统相当复杂,但仍然基于Java/C#的基础。另一方面,Go的面向对象部分看起来非常不同。我没有尝试过Go,因为我觉得它太像C,太底层。作为一个Java程序员,我知道C#在技术上领先,并且有很多在Java中缺失的好特性。学习Scala扩宽了我的视野,让我在不失去面向对象世界的好东西的同时,拥有函数式代码的优势和力量。在Java监狱里度过的这些年,用Scala编程是一种真正令人耳目一新和令人惊叹的经历。

英文:

I don't think so, at least conceptually they are very different. Go is much more C++ like and "low level" oriented than C#, and C# has only a few functional features while Scala allows you to write typical "functional" Code (more verbose than OCaml or Haskell, but similar). Scala's type system is quite sophisticated, but is nevertheless based on a Java/C#-like foundation. On the other hand, Go's object-oriented part looks quite different. I didn't try out Go, as I found it too C-like and too low-level. As a Java programmer I know that C# is technically ahead and has a lot of nice features missing in Java. When learning Scala it widened my view, giving me the advantage and power of functional Code without losing the good things from the object oriented world. After the years in Java jail programming in Scala is a really refreshing and mindblowing experience.

答案3

得分: 10

Go只是另一种仍处于初级阶段的命令式语言。截至目前,Go没有泛型。此外,它也不支持函数式编程。

C#是一种面向对象/命令式语言,对函数式编程的支持非常有限。它具有泛型。当前版本不支持协变和逆变注释(尽管它们计划在下一个版本的语言中支持)。

Scala是一种混合语言,试图将两个世界(即面向对象和函数式)的优点结合到一种语言中。从下图可以看出(来源:http://james-iry.blogspot.com/2010/05/types-la-chart.html),Scala拥有一个非常复杂的文件系统,这是C#和Go所缺乏的。

Go-Scala-Go!主要有哪些区别?

因此,就功能而言,Scala是这三种语言中最丰富的语言(考虑到面向对象和函数式特性)。C#确实提供了一些函数式构造,但与Scala相比远远不及。在我看来,将Go与Scala/C#进行比较就像将牛车与兰博基尼进行比较。

英文:

Go is just another imperative language which is still in diapers. As of now, Go doesn't have generics. Also there's no support for functional programming.

C# is an OO / imperative language with a very little support for functional programming. Has Generics. Current version doesn't support Covariance and Contravariance annotations (though they're planned for the next version of the language).

Scala is a hybrid language that tries to combine the best of both worlds (namely, OO and functional) into one language. As can be seen from the following figure (Source: http://james-iry.blogspot.com/2010/05/types-la-chart.html), Scala has got a very sophisticated file system, something that both C# and Go lack.

Go-Scala-Go!主要有哪些区别?

So featurewise, Scala is the most feature-rich language (considering both OO and functional features) of the three. C# does provide some functional constructs but it's nowhere close to Scala. And IMO comparing Go with Scala / C# is like comparing bullock cart with a Lamborghini.

答案4

得分: 1

我看到有些人几乎直接将Java代码转换为Go代码,将C代码转换为Go代码等等。我现在看到你几乎可以直接将Scala代码转换为Go代码。当语言具有相似的起源时,这通常不难做到。然而,比较应该是针对专门利用特定语言习惯用法编写的代码。我最近看了一些依赖指针的C代码几乎直接转换为Go代码。它不仅阅读起来很痛苦,而且执行起来也非常慢。

此外,为了补充MJP在Scala中埃拉托斯特尼筛法的示例,请查看《Go编程语言教程》中的素数部分,详细描述了Go中习惯用法的并发编程实现的埃拉托斯特尼筛法。

英文:

I've seen some people almost directly convert Java code to Go code, C code to Go code, etc. I now see you can almost directly convert Scala code to Go code. When languages have a similar heritage, that's often not hard to do. However, the comparison should be between code written specifically to take advantage of the idioms of a particular language. I recently looked at some pointer dependent C code converted almost directly to Go code. It was not only painful to read; it was also painfully slow.

And, to complement MJP's example of the Sieve of Eratosthenes in Scala, look at the Prime numbers section of A Tutorial for the Go Programming Language for a detailed description of an idiomatic concurrent programming implementation of the Sieve of Eratosthenes in Go.

huangapple
  • 本文由 发表于 2010年7月2日 20:13:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/3165525.html
匿名

发表评论

匿名网友

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

确定