dongni8969
2010-07-02 12:13 浏览 16

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答 默认 最新

  • 已采纳
    douban2014 douban2014 2010-07-02 13:08

    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.

    点赞 评论 复制链接分享
  • douzhi1919 douzhi1919 2010-07-02 14:27

    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.

    点赞 评论 复制链接分享
  • doutui2883 doutui2883 2010-07-02 14:58

    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.

    点赞 评论 复制链接分享
  • duanlu1279 duanlu1279 2010-07-02 16:30

    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.

    点赞 评论 复制链接分享

相关推荐