Go (programming language)
![]() |
|
Paradigm | compiled, concurrent, imperative, structured |
---|---|
Appeared in | 2009 |
Designed by | Robert Griesemer Rob Pike Ken Thompson |
Developer | Google Inc. |
Stable release | r58[1] (2011-06-29) |
Typing discipline | strong, static |
Major implementations | gc (8g, 6g, 5g), gccgo |
Influenced by | C, Limbo, Modula, Newsqueak, Oberon, Pascal[2] |
OS | Linux, Mac OS X, FreeBSD, MS Windows, Plan 9[3] |
License | BSD-style[4] |
Usual filename extensions | .go |
Website | golang.org |
Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.[5]
The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson,[2] building on previous work related to the Inferno operating system.[6] Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being used "for real stuff" at Google.[7] Go's "gc" compiler targets the Linux, Mac OS X, FreeBSD, and Microsoft Windows operating systems and the i386, amd64, and ARM processor architectures.[8]
Contents |
Goals
Go aims to provide the efficiency of a statically-typed compiled language with the ease of programming of a dynamic language.[9] Other goals include:
- Safety: type-safe and memory-safe.
- Good support for concurrency and communication.
- Efficient, latency-free garbage collection.
- High-speed compilation.
Description
The syntax of Go is broadly similar to that of C: blocks of code are surrounded with curly braces; common control flow structures include for
, switch
, and if
. Unlike C, line-ending semicolons are optional; variable declarations are written differently and are usually optional; type conversions must be made explicit; and new go
and select control keywords have been introduced to deal with concurrent programming. New built-in types include maps, Unicode strings, array slices, and channels for inter-thread communication.
Go is designed for exceptionally fast compiling times, even on modest hardware.[10] The language requires garbage collection. Certain concurrency-related structural conventions of Go (channels and alternative channel inputs) are borrowed from Tony Hoare's CSP. Unlike previous concurrent programming languages such as occam or Limbo, Go does not provide any built-in notion of safe or verifiable concurrency.[11]
Of features found in C++ or Java, Go does not include type inheritance, generic programming, assertions, method overloading, or pointer arithmetic.[2] Of these, the Go authors express an openness to generic programming, explicitly argue against assertions and pointer arithmetic, while defending the choice to omit type inheritance as giving a more useful language.[2] Initially, the language did not include exception handling, but in March 2010 a mechanism known as panic
/recover
was implemented to handle exceptional errors while avoiding some of the problems the Go authors find with exceptions.[12][13]
Visibility of structures, structure fields, variables, constants, methods, top-level types and functions outside of their defining package is defined implicitly according to the capitalization of their identifier.[14]
Implementations
There are currently two Go compilers:
- 6g/8g/5g (the compilers for AMD64, x86, and ARM respectively) with their supporting tools (collectively known as "gc") based on Ken's previous work on Plan 9's C toolchain.
- gccgo, a GCC frontend written in C++,[15] and now officially supported as of version 4.6, albeit not part of the standard binary for gcc.
Both compilers work on Unix-like systems, and a port to Microsoft Windows of the gc compiler and runtime have been integrated in the main distribution. Most of the standard libraries also work on Windows.
There is also an unmaintained "tiny" runtime environment that allows Go programs to run on bare hardware.[16]
Examples
The following is a Hello world program in Go:
package main import "fmt" func main() { fmt.Println("Hello, World") }
Go's automatic semicolon insertion feature requires that opening braces not be placed on their own lines, and this is thus the preferred brace style; the examples shown comply with this style.[17]
Example illustrating how to write a program like the Unix echo command in Go:[18]
package main import ( "os" "flag" // command line option parser ) var omitNewline = flag.Bool("n", false, "don't print final newline") const ( Space = " " Newline = "\n" ) func main() { flag.Parse() // Scans the arg list and sets up flags var s string for i := 0; i < flag.NArg(); i++ { if i > 0 { s += Space } s += flag.Arg(i) } if !*omitNewline { s += Newline } os.Stdout.WriteString(s) }
Reception
Go's initial release led to much discussion.
David Given compared it unfavorably to another programming language "Brand X," which was finally revealed to be Algol 68, commenting that this showed an overall lack of progress in procedural programming language design over the course of the intervening 41 years.[19]
Michele Simionato wrote in an article for artima.com:[20]
Here I just wanted to point out the design choices about interfaces and inheritance. Such ideas are not new and it is a shame that no popular language has followed such particular route in the design space. I hope Go will become popular; if not, I hope such ideas will finally enter in a popular language, we are already 10 or 20 years too late :-(
Dave Astels at Engine Yard wrote:[21]
Go is extremely easy to dive into. There are a minimal number of fundamental language concepts and the syntax is clean and designed to be clear and unambiguous. Go is still experimental and still a little rough around the edges.
Blogger Michael Hoisie wrote:[22]
Overall I think Go will find a good niche - a high performance language that's suitable for most system tasks. It has a great initial library, and it seems to have attracted a large community already (the irc chat room currently has over 500 users).
Ars Technica interviewed Rob Pike, one of the authors of Go, and asked why a new language was needed. He replied that:[23]
It wasn't enough to just add features to existing programming languages, because sometimes you can get more in the long run by taking things away. They wanted to start from scratch and rethink everything. ... [But they did not want] to deviate too much from what developers already knew because they wanted to avoid alienating Go's target audience.
Go entered the TIOBE Programming Community Index at fifteenth place in its first year,[citation needed] surpassing established languages like Pascal. As of 25 May 2011 , it is ranked 25th in the index.[24]
Naming dispute
On the day of the general release of the language, Francis McCabe, developer of the Go! programming language (note the exclamation point), requested a name change of Google's language to prevent confusion with his language.[25] While McCabe has not trademarked the name, some commenters on McCabe's request called for Google to adopt a new one. The issue was closed on 12 October 2010 with the custom status "Unfortunate", the closing Google developer stating that "there are many computing products and services named Go. In the 11 months since our release, there has been minimal confusion of the two languages."[26]
Concurrency
Go provides goroutines, small lightweight threads; the name alludes to coroutines. Goroutines are created with the go
statement from anonymous or named functions.
Goroutines are executed in parallel with other goroutines, including their caller. They do not necessarily run in separate threads, but a group of goroutines are multiplexed onto multiple threads — execution control is moved between them by blocking them when sending or receiving messages over channels.
See also
References
- This article incorporates material from the official Go tutorial, which is licensed under the Creative Commons Attribution 3.0 license.
- ^ http://golang.org/doc/devel/release.html
- ^ a b c d "Language Design FAQ". golang.org. 2010-01-16. http://golang.org/doc/go_faq.html. Retrieved 2010-02-27.
- ^ "Go Porting Efforts". Go Language Resources. cat-v. 2010-01-12. http://go-lang.cat-v.org/os-ports. Retrieved 2010-01-18.
- ^ "Text file LICENSE". http://golang.org/LICENSE. Retrieved 2011-01-27.
- ^ Kincaid, Jason (2009-11-10). "Google’s Go: A New Programming Language That’s Python Meets C++". TechCrunch. http://www.techcrunch.com/2009/11/10/google-go-language/. Retrieved 2010-01-18.
- ^ "Source file src/cmd/goyacc/goyacc.go". golang.org. http://golang.org/src/cmd/goyacc/goyacc.go. Retrieved 2010-01-18. "Derived from Inferno's utils/iyacc/yacc.c
http://code.google.com/p/inferno-os/source/browse/utils/iyacc/yacc.c" - ^ Metz, Cade (2010-05-20). "Google programming Frankenstein is a Go". The Register. http://www.theregister.co.uk/2010/05/20/go_in_production_at_google/.
- ^ "Installing Go". golang.org. The Go Authors. 2010-06-11. http://golang.org/doc/install.html#tmp_33. Retrieved 2010-06-11.
- ^ Pike, Rob. "The Go Programming Language". YouTube. http://www.youtube.com/watch?v=rKnDgT73v8s&feature=related. Retrieved 1 Jul 2011.
- ^ Rob Pike. (2009-11-10) (flv). The Go Programming Language. [Tech talk]. Google. Event occurs at 8:53. http://www.youtube.com/watch?v=rKnDgT73v8s#t=8m53.
- ^ "The Go Memory Model". Google. http://golang.org/doc/go_mem.html. Retrieved 5 January 2011.
- ^ Release notes, 3/30/2010
- ^ "Proposal for an exception-like mechanism". golang-nuts. 2010-03-25. http://groups.google.com/group/golang-nuts/browse_thread/thread/1ce5cd050bb973e4. Retrieved 2010-03-25.
- ^ "A Tutorial for the Go Programming Language". The Go Programming Language. Google. http://golang.org/doc/go_tutorial.html. Retrieved 2010-03-10. "In Go the rule about visibility of information is simple: if a name (of a top-level type, function, method, constant or variable, or of a structure field or method) is capitalized, users of the package may see it. Otherwise, the name and hence the thing being named is visible only inside the package in which it is declared."
- ^ "FAQ: Implementation". golang.org. 2010-01-16. http://golang.org/doc/go_faq.html#Implementation. Retrieved 2010-01-18.
- ^ Gerrand, Andrew (February 1, 2011). "release.2011-02-01". golang-nuts. Google. http://groups.google.com/group/golang-nuts/browse_thread/thread/b877e34723b543a7. Retrieved 2011-02-05.
- ^ "A Tutorial for the Go Programming Language". The Go Programming Language. Google. http://golang.org/doc/go_tutorial.html. Retrieved 2010-03-10. "The one surprise is that it's important to put the opening brace of a construct such as an if statement on the same line as the if; however, if you don't, there are situations that may not compile or may give the wrong result. The language forces the brace style to some extent."
- ^ "A Tutorial for the Go Programming Language". golang.org. 2010-01-16. http://golang.org/doc/go_tutorial.html. Retrieved 2010-01-18.
- ^ Given, David (2009-11-15). "On Go". http://www.cowlark.com/2009-11-15-go/. Retrieved 2011-03-29.
- ^ Simionato, Michele (2009-11-15). "Interfaces vs Inheritance (or, watch out for Go!)". artima. http://www.artima.com/weblogs/viewpost.jsp?thread=274019. Retrieved 2009-11-15.
- ^ Astels, Dave (2009-11-09). "Ready, Set, Go!". engineyard. http://www.engineyard.com/blog/2009/ready-set-go/. Retrieved 2009-11-09.
- ^ Hoisie, Michael (2009-11-11). "My thoughts on the Go Programming language". hoisie dot com. http://www.hoisie.com/post/my_thoughts_on_the_go_programming_language. Retrieved 2009-11-11.
- ^ Paul, Ryan (2009-11-10). "Go: new open source programming language from Google". Ars Technica. http://arstechnica.com/open-source/news/2009/11/go-new-open-source-programming-language-from-google.ars. Retrieved 2009-11-13.
- ^ "TIOBE Programming Community Index for January 2010". TIOBE Software. January 2010. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html. Retrieved 2011-05-25.
- ^ Claburn, Thomas (2009-11-11). "Google 'Go' Name Brings Accusations Of Evil'". InformationWeek. http://www.informationweek.com/news/software/web_services/showArticle.jhtml?articleID=221601351. Retrieved 2010-01-18.
- ^ "Issue 9 - go - I have already used the name for *MY* programming language". Google Code. Google Inc.. http://code.google.com/p/go/issues/detail?id=9. Retrieved 2010-10-12.
External links
- Official website
- Pike, Rob (28 April 2010). "Another Go at Language Design". Stanford EE Computer Systems Colloquium. Stanford University. http://www.stanford.edu/class/ee380/Abstracts/100428.html. (video) — A university lecture
- "Episode 0.0.3 - Google’s Go Programming Language". The Changelog. 27 November 2009. http://thechangelog.com/post/259401776/episode-0-0-3-googles-go-programming-language. — Podcast interview with Rob Pike, Tech Lead for the Google Go team
- Go Programming Language Resources (unofficial)
- irc://chat.freenode.net/#go-nuts – the IRC channel #go-nuts on freenode