去斯卡拉去吧!主要区别是什么?

发布于 2024-09-08 10:30:29 字数 227 浏览 4 评论 0原文

我刚刚发现这个 网页 比较了用 Scala、C# 和去。我惊讶地发现 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泛滥成性 2024-09-15 10:30:29

老实说,Scala 代码是用极其命令式的风格编写的。我不是函数纯粹主义者,但将该页面的埃拉托斯特尼筛法代码与 Stream 类。该页面的代码到处都有大量的变量和 while 循环,更不用说位移了。现在,我不知道对于什么是惯用的 Scala 代码有多少共识,但这绝对是相去甚远。因此,除了 Scala 和 Go 都是 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.

葬花如无物 2024-09-15 10:30:29

我不这么认为,至少在概念上它们有很大不同。 Go 比 C# 更像 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.

素年丶 2024-09-15 10:30:29

Go 只是另一种仍处于尿布阶段的命令式语言。到目前为止,Go 还没有泛型。此外,也不支持函数式编程。

C# 是一种面向对象/命令式语言,对函数式编程的支持很少。有泛型。当前版本不支持协方差和逆变注释(尽管它们计划用于该语言的下一版本)。

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

alt text http://www.pogofish.com/types.png

因此,就功能而言,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.

alt text http://www.pogofish.com/types.png

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.

躲猫猫 2024-09-15 10:30:29

我见过有些人几乎直接将Java代码转换为Go代码,C代码转换为Go代码等。我现在看到你几乎可以直接将Scala代码转换为Go代码。当语言具有相似的传统时,这通常并不难做到。但是,应该在专门为利用特定语言的习惯用法而编写的代码之间进行比较。我最近查看了一些几乎直接转换为 Go 代码的依赖于指针的 C 代码。读起来不仅痛苦,而且痛苦。速度也慢得令人痛苦。

并且,为了补充 MJP 在 Scala 中的埃拉托斯特尼筛法示例,请查看 A 教程的素数部分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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文