The Go language vs. Scala language

Source: Internet
Author: User

I've written about go (my spare time) at Google and I've written Scala on LinkedIn. Both are modern languages with best-in-class concurrency features.

The following answer is based on my experience of writing large-scale software.

Go is a language in which the development pattern is rigidly fixed and compiled into machine code with minimal code amount.

Scala is a complex, academic, functional, object-oriented sandbox language that has many features and runs on the JVM.

One of the reasons I would prefer go instead of Scala for any project of the vast majority of developers is: simple.

1th paragraph (1.15 points can be obtained) 0matthew3 months ago

Before I start answering questions, I want to make some basic observations:

    • In general, less code is easier to understand, but one thing is that the code is so dense that it's hard to read.
    • The code reads much more than it writes.
    • The life of the code is longer than we want it to be.
    • The person who tests or maintains a piece of code is often not the original author.
    • On a scale, the skill level of the developer who reads/Writes/maintains/tests the code will be the normal distribution in the sense of "non-expert".

Writing code is a communication behavior that is not only the communication between the author and the compiler (or runtime), but also the communication between the author and the future reader of the unknown skill level.


The complexity of language

The Java 8 language specification is a 780-page PDF.
Http://docs.oracle.com/javase/sp ...

The Scala language specification is a 191-page PDF.
Http://www.scala-lang.org/docu/f ...

The Go language specification is a Web page, printed as a 51-page PDF.
Http://golang.org/ref/spec

Defining a language is not the same as learning how to use a language, but it represents the content of learning (or the number of things that can confuse you when reading someone's code).


Simplified instruction set computer vs. complex instruction Set Computer


Go provides a small set of orthogonal primitives that interact with each other in a clear and predictable way. Learn a small amount of primitives and build what you need with more lines of code than Scala.
Scala offers a large number of types and syntax toolboxes. Learn a lot of primitives, know when to use each one, and you'll be able to write fewer lines of code than go.

File


I found a much easier way to learn because it was a simpler language and subjective because I thought the document was better.
Show:
Http://docs.scala-lang.org/tutor ...

Vs
http://tour.golang.org/#1
Http://golang.org/doc/effective_ ...

Frequently Asked Questions:
Http://docs.scala-lang.org/tutor ...
Vs
Http://golang.org/doc/faq

Standard library:
Http://www.scala-lang.org/api/cu ...
Vs
http://golang.org/pkg/

Expressive ability

Given the language specifications, it's no surprise that Scala has more features than go.

One of the features of Go is that it has no extra functionality, and frankly, I think its function is underestimated.
Http://golang.org/doc/faq#Why_do ...

Does this mean that go is less expressive than Scala?
No.
Expression means "effective communication of thought or feeling", which does not mean "which language is most distinctive". In practice, the expressiveness of the code depends more on the author than on the language in which it is used.
Code density can be counterproductive to expression.

Simulating city effects

Don't use Google search, I just made it up. You know the city of simulation, right?
SimCity Official Website

If two people build a new city on the same map and operate for a few hours, they will produce a completely different city.

What is this for?
Because the simulation city is like a sandbox, there are too many choices, so any two people will make the same decision, which is very unlikely.
Scala is also a sandbox.
In addition to the many features that Scala comes with (functional programming features, OO programming features, and so on), Scala also exposes the ability to allow developers to add new features.
It's all good, unless you share your sandbox with others, or they don't know what's in your head.

Consistency of code

Go is the only thing I know. By providing a tool to format code in canonical format, this avoids the entire code style controversy.
http://golang.org/cmd/gofmt/

Code density

In the early stages of learning, Scala code can be very dense and difficult. What I want to say is that being as dense as possible in Scala is very experienced, or at least an experienced Scala developer with a neat tendency.

2nd paragraph (8.68 points can be obtained) 0 North Star Polaris1 week ago

For example

Consider obtaining a user ID from a cookie. How much language knowledge do you need to answer the following questions?

    • What happens if a cookie doesn't exist?
    • What happens if the cookie value is not a well-formatted number?
    • What happens if the cookie value is negative?

Scala

import play.api.mvc.RequestHeader def getUserId()(implicit request: RequestHeader) = {  request.cookies.get("uid").map(_.value.toLong).filter(_ > 0)}

Go

Import ("FMT""http""StrConv")Funcgetuserid (R *http. Request)  (int64, error) {c, err: = R.cookie (" UID ") if err! = nil { return 0, err} i, err: = StrConv. parseint (C.value, 10, 64) if err! = Span class= "Hljs-literal" >nil {return 0, err} if i <= 0 {return 0 Fmt. Errorf ( "Invalid User ID")} return I, nil}             
3rd paragraph (0.7 points can be obtained) 0 Sunglasses big head 1 years ago

in this particular case, The Scala code is short and perhaps more persuasive, but one thing I want to show is that the code for Go is explicit and Scala's code needs context to understand it.

Display of $#%!ing

In my experience, there are many benefits to explicit code.

    • Explicit code makes it easier for novice and non-author spirits to communicate.
    • Explicit code is easier to edit small changes.
    • Explicit code makes the error situation clearer.
    • Explicit code makes the test case clear.
    • Explicit code is easier to debug (try setting breakpoints in the previous Scala code).
4th paragraph (1.28 points can be obtained) 0 Sunglasses big head 1 years ago

I found the code for GO is much clearer than Scala.

Performance

As a developer, performance was the only thing I cared about in the development cycle because I didn't want to run into a runtime that wasn't fast enough when I wanted to. In any case, developers ' time is more valuable than computer time.

According to my experience, go compiles very much, and Scala is relatively slow. Vary.

A fair word.

I learned about go before I studied Scala, so I admitted that I was more inclined to go. My first reaction to go is that its syntax is hard to read (like C + +) But learning go feels like this:

I am learning scala out of necessity and have gotten used to it; I even like it now, but learning Scala is the feeling:

The Go language vs. Scala language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.