Why do I use Go to program

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The Go language, as a novel programming language, was originally invented by Google for server development. And its inventors are a number of highly accomplished, skilled computer science experts: like Ken Thompson and Rob Pike the old friend. One of the most important products I've recently published has gone to go development, and the Go language proves its superior features in terms of developer productivity and product performance. Because of this, many other development teams I know are also preparing go to go (oh, how smart is the name of the language!) )。

Think about it, how long will it take you to meet a programming innovation that takes into account both development efficiency and computational performance?

Before discussing the go language, I want to talk about why I like TA. I started developing small Web applications in 2001 and started to get in touch with a wide variety of languages. I was an absolute loyal fan of C + + at that time. By the 2004, I began to touch PHP (non-object oriented). But it wasn't long before I hated PHP. I can't catch any errors at all, especially before I run the program. Just then, I realized that the following two programming concepts are important:

1. "Object-oriented" is only a way of programming, not the only one. And sometimes, it's not necessarily the best choice.

2. Scalar (shape, character, String, float, Boolean type), Sequence (list, array) and mapping (name value pairs) These language built-in types, in fact, have basically met most of the data structure requirements.

php creative scenes for small applications There's absolutely nothing to say. 。 But it is difficult to test, difficult to debug (too many implicit type conversions) and too slow. When I wanted to get out of PHP for a while, I bumped into Java in 2007. Java may be the most depressing language I've ever met. Java is too strict and meaningless (in other words too redundant) and too "bulky", including various Ides, frameworks, build environment configurations, and so on. We need to complete the tedious configuration before we can start development. At the same time, I don't accept the idea of the JVM (Java virtual machine). Its illusory portability brings a painful price.

2008, I began to touch Python. I used TA to try Sledgehammer 5 years ago, but now I devote myself to it. I like Python. It supports multi-paradigm, language is very semantic, there are many highlights of the east, such as list parsing, generator expressions, adorners, keyword parameters (**kwargs) and so on. Its semantic clarity, design   > Close.

but, Python has a prominent problem, is that it is not fast. I have used an optimizer like Psyco, but the effect is not ideal. And then tried the unladen swallow Optimizer, but also not ideal.

When I started using Python, I found that Google had a unique passion for TA. Guido van Rossum , the father of Python, worked for Google. After a while, I heard a new language from Google was born-go. If go is not behind the fame of Rob and Ken, and the world's greatest IT company, the project may have been disbanded at the experimental stage.

When the Go language was released in 2009, I didn't realize why it was so great, except that the go contains a lot of modern language structures and runs fast.


Now let's pause for a moment and change the subject.

At the end of 2010, when I was working at Zynga, I had a bit of time to go back to using PHP from Python. So I took a little time to read something. Among the books I have read, there is a book in which some of the discussions describe the concept of "Data Flow Programming" (Dataflow programming) and "declarative Concurrency" (declarative concurrency). You may need to go through the previous link, To get a quick look at this concept, as this is the core feature of the go language.


When I was learning data flow programming, I remembered  

A while earlier last year, We discuss and try to find other programming languages that are more specific and performance-oriented than PHP-the compiled language.  

The practice based on go

After using go to develop some project prototypes, I have a more specific experience:

  1. powerful features from the compiler : programming with a compiled language is a pleasant thing to do. The compiler does not only check the code that could cause a run-time exception, but it does not allow the existence of the code to the fullest extent. Of course, this is not the Go Language feature, but the Go language compiler also provides this functionality.
  2. Standard Code formatting features: in team development, Code Implementation Unified Formatting Standards is very necessary, so the code formatting tool is a popular feature that reduces the "Not My Code" psychological barrier.
  3. Thin language Features: Go is a very compact language, language features are also very streamlined, at the language level, it retains only the necessary, mature, determined language features, at this point it is more similar to the C language, so it is easy to learn and suitable for writing programs.
  4. built-in Strong features: Whether you're writing a Web server program, a raw socket server program, or any other program that needs to call OS built-in functions , The Go standard library has a large number of corresponding packages.
  5. Simple and easy to use concurrency library: Go channel and goroutine can handle concurrency very well, using these 2 features, you can handle concurrency without writing event handlers for the entire program like node. js, Twisted.
  6. Getting Started is simple: and other needs Configuration compared to the language of the IDE, the context of the Go language The entry time will be much less.
  7. Rapid development: go is highly productive and includes a large number of components that the server program needs to use, so you can write your server-side code in a very short period of time. Less code means faster troubleshooting.
  8. suitable for multicore , High-performance environments : Go's rumtime is surprisingly fast and stable at run time, and for that, programmers who write server code in Python will feel better. Unlike the languages of Python and node. js, the runtime of Go can produce multiple OS threads and run them in parallel.

Using Go in the product

Some of the features of Go language you can only experience in the product, I really like the following aspects of the Go language:

  1. single binary file: Go generates a statically linked binary file that can be run on any build target platform. This is especially good for cloud-based publishing environments, because you only need a simple OS image. In contrast, other dependent settings that need to be crafted are much worse.
  2. Cross-platform compilation: I mentioned earlier about the tradeoffs that the JVM made about portability. In fact, only a few Java programs need to be ported to different systems. Because of the need to be coupled with dependency management of the target system, Java becomes a bit of a rogue. The Go language can be developed on any machine, only to be compiled on the target platform. All I need to do is replicate the cross-compiled binaries for portability.
  3. built-in anatomy: with only a few lines of code, you can implement an HTTP service that provides real-time information such as CPU, memory, go programs, OS threads, lock contention, and so on. You can use the tool chain of the go language to access URLs and provide profiled data within your app. That's amazing!
  4. Shareable code: The biggest obstacle to code sharing is the size of the project, or the amount of code. Even if people have access to some code base, it is not easy to understand the code in depth. Because it uses a handful of lines of code to implement the same functionality in C + + or Java, it makes the code more readable and easier to share. The limited language specification also means that it is unlikely to cause some people to fall into obscure constructs or "advanced features".

Summarize

In short, I found that go is by far the most useful sever-side programming language, it has the Python language elegance and the advantages of C + + high-performance, to step back, even if it only has the Python 90% ease of use and C + + 90% high performance, it is also good, And it has many advantages: 1. The go language-based program is easier to develop and deploy in heterogeneous platforms and virtual environments than other languages; 2) The Go language facilitates sharing and collaborative development because it has a single standard, streamlined language feature.


Note:

Translation from Http://www.oschina.net/translate/why-program-in-go

Translated from http://tech.t9i.in/2013/01/why-program-in-go/

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.