Go language: Language based on connection and combination (top)

Source: Internet
Author: User
Tags arrays command line data structures inheritance stdin

So far, I've done more than 10 lectures on go, most of which are related to topics like "design philosophy." This is because I am positioning myself as the "preacher" of the Go language, not the "trainer". My starting point is to arouse everyone's attention and interest in go, as for how to learn the grammar of the goes step-by-step, I believe that interest is the best teacher. Now we learn the platform is strong enough, as long as you are really interested, you will be able to learn the go language.

The go language is a very simple language. Simplicity means fewer than a few. The Go language strives for the minimization of linguistic features, and if a certain grammatical feature is just a few lines of code, but does not have an essential effect on the difficulty of solving the actual problem, such grammatical features will not be added. The go language is more concerned with how to solve the mental burden of programmer development. How to reduce the chance of code error and how to write high quality code more easily is a matter of great concern when go design.

The go language is also a language that pursues nature very much. Go does not only provide very few language features, but also strives to pursue the most natural expression of linguistic features, which are designed to avoid surprises as many people expect. In fact, there is very little controversy about the grammatical characteristics of the go language. These also make the entry threshold for the go language very low.

Today, my focus is on the genre of Go programming paradigm. This is still about "philosophy of design". The programming paradigm that you may have heard so far is mainly as follows:

Procedure (Representative: C)

Object Oriented (representative: Java, C #)

Message oriented (representative: Erlang)

Function (representative: Haskell, Erlang)

The representative concept of programming is the process (function). This is a very old genre, and basically all languages have procedural shadows. But the more pure process-style of the mainstream language is relatively small, usually relatively old, C is one of the most typical representative.

Object-oriented programming is one of the most widely accepted and far-reaching schools at present. There are many concepts of object-oriented: Classes, Methods, properties, Overloads, polymorphic (virtual functions), constructs and destructors, inheritance, and so on. Java, C # is one of the most typical representatives. The go language supports object-oriented, but minimizes features. In the go language there are structures (similar to objects in object-oriented classes), and structs can have methods, which is all the content of the get-object support. The go language has very little object-oriented features. Structure is the foundation of composite objects, as long as there is a combination, usually by the structure, such as C, such as the process of language, so there is a structural body. So there's not a lot of object-oriented branding on go, and go even opposes inheritance, refusing to provide inheritance syntax.

Message-oriented programming is a relatively small genre of programming, because of the strong demand for distributed and concurrent programming rise. The main idea of message-oriented programming is to recommend concurrent programming based on message rather than lock and shared memory. The Erlang language is a representative of message-oriented programming. There is a message-oriented shadow in the go language. Because there are channel in the Go language, you can let the execution body (goroutine) send messages to each other. But channel is just the basic grammatical feature of the go language, and go doesn't eliminate locks and shared memory, so it's not a message-oriented programming genre.

Functional programming is also a niche genre, albeit with a very long history. There are some concepts in functional programming, such as closure, curry, variable immutable and so on. Haskell and Erlang are all representatives of this genre. Functional programming is a small audience, the most important reason is that the theoretical basis is not widely known. We lack the data structure of the function-oriented programming. Because variables are immutable, data structure studies need to be expressed in completely different ways of thinking. For example, in traditional imperative programming, arrays are the simplest basic data structures, but in functional programming, arrays are difficult to provide (modifying an element of an array is too expensive, and the data structure of an array in Erlang language is introduced late, using tree to simulate an array). The go language does not have too many functional shadows in addition to supporting closures.

The go language has the shadow of each of these genres, but it only absorbs the most basic concepts of these genres, which are very basic and difficult to see as a key feature of a genre. So from the programming paradigm, the individual thinks that the go language does not belong to any of these genres. If you want to say a genre, go language similar to C + +, should be considered "multiple paradigm" genre. C + + is the mainstream language, and is almost the only language that advocates the idea of multiple paradigm programming. C + + main support programming paradigm is procedural programming, object-oriented programming, generic programming (we do not include generic programming in the discussion genre). C + + for the main characteristics of these schools support is very complete, say "multi-paradigm" worthy of the word. But go is not the same, each genre of feature support is very basic, these features can only be called function, and did not form a paradigm.

The go language, on the basis of absorbing the essence of these genres, has created its own unique programming style: a language based on connection and combination.

A connection is the way in which a component is coupled, that is, how the component is concatenated. Combination is the basis for forming compound objects. Connection and combination are very common concepts in the language, but the go language is just in the ordinary to see magic.

Let's talk about it from UNIX. The go language has deep roots with Unix and C languages. Go-language leaders are involved in and even dominate the design of Unix and C languages. Ken Thompson is even the originator of UNIX and C language. The go language is also deeply influenced by the design philosophy of Unix and C languages.

In the UNIX world, components are applications (apps), and each app can be roughly abstracted as:

Input: stdin (standard input), params (command line arguments)

Output: stdout (standard output)

Protocol: text (data stream)

How does a different application (APP) connect? The answer is: pipe (pipeline). In the Unix world, people are already familiar with such things:

App1 Params1 | APP2 PARAMS2

Through pipelines (pipeline), you can convert an application's output (stdout) to another application's input (stdin). The more magical point is that these applications are executed in parallel. App1 will be processed by APP2 as soon as each output is generated. So the pipeline (pipeline) is the oldest, but also extremely excellent parallel facilities, simple and powerful.

It is to be noted that different applications in the UNIX world are directly loosely coupled. The upstream app's output is XML or JSON, and downstream apps need to be known, but without any enforcement constraints. The same output, different downstream app, may not even be the same understanding of the Protocol. For example, upstream app output a piece of XML text, for a downstream app, is a DOM tree, but for the LineCount program is just a multiline text, for the English word frequency Statistics program, is an English article.

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.