This is a creation in Article, where the information may have evolved or changed.
The graph is from Gopher illustration by Renee French.
time has gone too fast, flash eye Golang are five years old. Five years, for life may be a little long, but for the development of a language, is only bucket. Compared to the "system-level" language it is trying to challenge: c,c++, even Java,golang is still young, like a marathon, where others have run out of half a horse, and Golang just crossed the threshold line. The most reviled GC says that Golang is as rough as a toy compared to a Java GC. In accordance with Golang's roadmap,1.5 release, which is next July, the Golang GC will have a "making Go acceptable for implementing a broad", according to official words. spectrum of systems requiring low response times "[1] . Note that the wording here is acceptable, not great, and not brilliant.
Youth also means immaturity. [2]in a part-time project that I did for others last year, I stumbled upon an issue where the go1.2 compiler was too large for an executable file that was improperly handled by a global variable (not using a BSS segment). Even I this kind of novice can find Golang problem, it is obvious that its maturity still waits for the market examination.
Young and immature, it means that there are not many people who dare to taste the early adopters. Despite the endorsement of Google's rounds of open-source projects such as Docker, Golang's use is still worrying: if you look at the Tiobe index of November [3], Golang is ranked 41, than the "niche" functional programming language of Haskell. Of course, Tiobe does not necessarily reflect the real data, as I have not searched for anything about golang content in the whole of November [4], I am afraid to be excluded from Golang users.
Said Golang bad, say it's good.
Language features such as concurrency support,messaging with channel,type inference,implicit interface,build into one giant Executable and so on do not have to repeat, the beholder, the person to see kinky. These features are seen by different programmers and have different insights. C programmers see these must be two eyes, but will be the performance, especially the processing of data thoughtput or latency doubt; Erlang programmers estimate that most features will be liked, but messaging and concurrency are dismissive , but the Python programmer is excited, but it will produce "if Python can produce a run-time executable, and no Gil as the elbow, that Golang there is market space" such wishful daydreaming.
So the language feature, does not become I applaud for golang reason. In my opinion, Golang has injected new ideas and vitality into software development, so that many of the "take it for granted" have new ideas, which is the most important.
Try to lift the twos.
First of allconcurrency is used as a means of parallelism in other languages, and in Golang it becomes an artifact that understands the coupling system and reduces complexity.。 If you haven't seen Rob Pike's concurrency is not parallelism[5], it is highly recommended to take a look, even if you are not a golang of fans. Perhaps born in the hands of the inventor of the Unix (Ken Thompson), Golang is the essence of Unix everywhere.chan/go
This pair of joy enemy, like a beating Genie, turns the immutable call relationship between functions into a pair, no, a group of pipes. The easiest thing to say isio.Copy()
:
Func Chat (A, b io. Readwritecloser) { Err_chan: = Make (chan error, 1) go CP (A, B, Err_chan) go CP (b, A, Err_chan) If err: = & lt;-Err_chan; Err! = Nil { log. PRINTLN (Err) } a.close () b.close ()} func cp (w IO). Writer, R io. Reader, Err_chan chan<-error) { _, err: = Io. Copy (W, R) Err_chan <-Err}
You can't imagine a more graceful code: It has full-duplex asynchronous communication between A/b two streams and tells you when an error occursChat()
The process, log errors and gracefully exit. For Golang, thechan/go
As a decoupled tool, the code is magical when used properly.
golang are worthy of the users of other languages to think about . Golang's language design is compromised, and it expects to bring the concurrency model to the mainstream. So it chooses C-like's grammar, walks imperative language's path, instead of making itself into functional language, like Haskell, and therefore, on the concurrency model, Golang chooses CSP model [6] because CSP has a friendly support for imperative language and does not have to use some strange syntax and novel concepts to express. By contrast, most functional language have chosen the actor model [7] , such as Erlang,scala. So what you see in Golang is Channel,erlang you see is process (actor), Goroutine in Golang is anonymous, the process in Erlang is PID; messages in Golang are sent synchronously , blocked
As a concurrent Language,golang the most criticized is that the pointer can also be passed in the channel. You know, the essence of concurrency is that don ' t share state. The father of Erlang, Joe Armstrong, writes in his "Programming Erlang":
We don ' t have shared memory. I have my memory. You have yours. We have both brains, one each. They is not joined together. To change your memory, I send you a message:i talk, or I wave my arms.
(digression: This is a good book, there are many ideas, even without erlang, can read)
So for Golang's concurrency support, the users of Erlang, or those with functional programming episodes, are absolutely disgusted. But Golang's designers have a reason: in order to allow C/java/python and other imperative language users to better accept Golang, but also has its philosophy:
Don ' t communicate by sharing memory, share memory by communicating.
AgainGolang's error handling is another mystery, in a world in which almost all mainstream languages support try/catch
architecture, "anti-human" uses a "primitive" way of returning errors that are similar to C by return values。 Yes, error handling can also have different gameplay. This approach is simple and clear, with effective applicationchan
(as in the example above), errors can also be like other supportedtry/catch
Language as bubble up.
I am not an expert in language design, so I would not be very professional to estimate why Golang is so designed. For a concurrency language, concurrency must be everywhere. If you use the anomaly mode, the problem is: When a goroutine has an unhandled error, who will handle the error? Nature is the main thread, which is the practice of other programming languages. However, is the main thread the best choice? Not necessarily. If you usetry/catch
Structure, there is no choice, but Golang returns an error by using the return value, giving the developer the option to give the error to which goroutine to handle. This can lead to interesting patterns, such as having a goroutine specifically responsible for filtering errors, only extremely serious bubble up to the main thread, allowing them to clean up resources and exit the program.
Of course, there are still some flaws in this approach with concurrency, so Golang needdefer
,panic
Andrecover
To help.
At lastGolang the code by convention to the extreme.。 Code behavior by convention to complete, the beginning of the function of capital letters automatically export,implicit interface and so on, so that other languages need additional code description of things here do not have to repeat, if not golang, I am afraid that many people can not imagine the inheritance could play this way. I'm not saying this is the best practice, but it'sio
[9]Andjavascript
Through the prototype inheritance let me eye-opening, another let me feel a bit, think about the practice.
Well, just write this.
I sincerely hope that Golang in the next five years to be able to shine, but also those with the program June is still and C language struggle with a part of the poor people [ten] can soon be in the arena of Golang. God horse, why can't Cheng write code with Golang? Alas, the Golang is not honest, support FreeBSD minimum version is 8, who can help me in 6.x/7.x creates Macintosh, must inform, to kneel.
Disclainer: Program June Golang experience less than a year, except Hello World Series Code, code number less than 5,000 lines, Caishuxueqian, this article if there are mistakes, please advise.
If you think this article is good, please praise it. Thanks a lot!
Welcome to subscribe to the public number "program Life" (search number Programmer_life). Each article is designed to be authentic and meet you 8 o'clock.
1. See HTTP://LLVM.CC/T/GO-1-4-GARBAGE-COLLECTION-PLAN-AND-ROADMAP-GOLANG-ORG/33
2. See https://code.google.com/p/go/issues/detail?id=6993
3. See http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
4. I was godoc directly, or golang.org.
5. See Https://www.youtube.com/watch?v=cN_DpYBzKso
6. See http://en.wikipedia.org/wiki/Communicating_sequential_processes
7. See Http://en.wikipedia.org/wiki/Actor_model
8. Golang has played a lot of flower life on this feature, see the decoupling part as described above
9. See my blog http://tchen.me/posts/2013-01-06-io-lang.html
10. Soft realtime is not required, Golang can replace C
View Original: http://www.zoues.com/2016/10/20/golang%e4%ba%94%e5%91%a8%e5%b2%81/