Go (programming language) - Wikipedia, the free encyclopedia

# Go (programming language)

From Wikipedia, the free encyclopedia
(Redirected from Golang)
Not to be confused with Go! (programming language), an agent-based language released in 2003.

| This article's lead section may not adequately summarize all of its contents. Please consider expanding the lead to provide an accessible overview of all of the article's key points. (March 2012)

Go
Paradigm(s) | compiled, concurrent, imperative, structured
Appeared in | 2009
Designed by | Robert Griesemer Rob Pike Ken Thompson
Developer | Google Inc.
Stable release | version 1.0.2[1] (14 June 2012; 2 months ago (2012-06-14))
Typing discipline | strong, static
Major implementations | gc (8g, 6g, 5g), gccgo
Influenced by | C, Limbo, Modula, Newsqueak, Oberon, Pascal,[2] Python
OS | Linux, Mac OS X, FreeBSD, OpenBSD, MS Windows, Plan 9[3]
License | BSD-style[4] + Patent grant[5]
Usual filename extensions | .go
Website | golang.org

Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.[6]

The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.[2] 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, OpenBSD, Plan 9, and Microsoft Windows operating systems and the i386, amd64, and ARM processor architectures.[8]

## [edit] 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.

## [edit] 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 support 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, encouraging heavy use of interfaces instead.[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]

## [edit] Type system

Go allows a programmer to write functions that can operate on inputs of arbitrary type, provided that the type implements the functions defined by a given interface.

Unlike Java, the interfaces a type supports do not need to be specified at the point at which the type is defined, and Go interfaces do not participate in a type hierarchy. A Go interface is best described as a set of methods, each identified by a name and signature. A type is considered to implement an interface if all the required methods have been defined for that type. An interface can be declared to "embed" other interfaces, meaning the declared interface includes the methods defined in the other interfaces.[11]

Unlike Java, the in-memory representation of an object does not contain a pointer to a virtual method table. Instead a value of interface type is implemented as a pair of a pointer to the object, and a pointer to a dictionary containing implementations of the interface methods for that type.

Consider the following example:

    type Sequence []int

    func (s Sequence) Len() int {
        return len(s)
    }

    type HasLength interface {
        Len() int
    }

    func Foo (o HasLength) {
        ...
    }

These four definitions could have been placed in separate files, in different parts of the program. Notably, the programmer who defined the `Sequence` type did not need to declare that the type implemented `HasLength`, and the person who implemented the `Len` method for `Sequence` did not need to specify that this method was part of `HasLength`.

## [edit] Name visibility

Visibility of structures, structure fields, variables, constants, methods, top-level types and functions outside their defining package is defined implicitly according to the capitalization of their identifier.[14]

## [edit] 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.

## [edit] 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.[16]

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.[17]

## [edit] Examples

### [edit] Hello world

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.[18]

### [edit] Echo

Example illustrating how to write a program like the Unix echo command in Go:[19]

    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)
    }

## [edit] Reception

Go's initial release led to much discussion.

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.

Ars Technica interviewed Rob Pike, one of the authors of Go, and asked why a new language was needed. He replied that:[22]

> 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 was in 15th place on the TIOBE Programming Community Index of programming language popularity in its first year, 2009,[citation needed] surpassing established languages like Pascal. As of March 2012[update], it ranked 66th in the index.[23]

Bruce Eckel stated:[24]

> The complexity of C++ (even more complexity has been added in the new C++), and the resulting impact on productivity, is no longer justified. All the hoops that the C++ programmer had to jump through in order to use a C-compatible language make no sense anymore -- they're just a waste of time and effort. Now, Go makes much more sense for the class of problems that C++ was originally intended to solve.

## [edit] 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] The issue was closed by a Google developer on 12 October 2010 with the custom status "Unfortunate", with a comment 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]

## [edit] See also

- Comparison of programming languages

## [edit] References

This article incorporates material from the official Go tutorial, which is licensed under the Creative Commons Attribution 3.0 license.

1. ^ "golang-announce: go1.0.2 released". https://groups.google.com/forum/#!msg/golang-announce/9-f_fnXNDzw/MiM3tk0iyjYJ. Retrieved 14 June 2012.
2. ^ a b c d "Language Design FAQ". golang.org. 16 January 2010. http://golang.org/doc/go_faq.html. Retrieved 27 February 2010.
3. ^ "Go Porting Efforts". Go Language Resources. cat-v. 12 January 2010. http://go-lang.cat-v.org/os-ports. Retrieved 18 January 2010.
4. ^ "Text file LICENSE". http://golang.org/LICENSE. Retrieved 27 January 2011.
5. ^ "Additional IP Rights Grant". http://code.google.com/p/go/source/browse/PATENTS. Retrieved 26 July 2012.
6. ^ Kincaid, Jason (10 November 2009). "Google’s Go: A New Programming Language That’s Python Meets C++". TechCrunch. http://www.techcrunch.com/2009/11/10/google-go-language/. Retrieved 18 January 2010.
7. ^ Metz, Cade (20 May 2010). "Google programming Frankenstein is a Go". The Register. http://www.theregister.co.uk/2010/05/20/go_in_production_at_google/.
8. ^ "Installing Go". golang.org. The Go Authors. 11 June 2010. http://golang.org/doc/install.html#tmp_33. Retrieved 11 June 2010.
9. ^ Pike, Rob. "The Go Programming Language". YouTube. http://www.youtube.com/watch?v=rKnDgT73v8s&feature=related. Retrieved 1 Jul 2011.
10. ^ Rob Pike (10 November 2009) (flv). The Go Programming Language (Tech talk). Google. Event occurs at 8:53. http://www.youtube.com/watch?v=rKnDgT73v8s#t=8m53.
11. ^ a b "The Go Memory Model". Google. http://golang.org/doc/go_mem.html. Retrieved 5 January 2011.
12. ^ Release notes, 30 March 2010
13. ^ "Proposal for an exception-like mechanism". golang-nuts. 25 March 2010. http://groups.google.com/group/golang-nuts/browse_thread/thread/1ce5cd050bb973e4. Retrieved 25 March 2010.
14. ^ "A Tutorial for the Go Programming Language". The Go Programming Language. Google. http://golang.org/doc/go_tutorial.html. Retrieved 10 March 2010. "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."
15. ^ "FAQ: Implementation". golang.org. 16 January 2010. http://golang.org/doc/go_faq.html#Implementation. Retrieved 18 January 2010.
16. ^ "Installing GCC: Configuration". http://gcc.gnu.org/install/configure.html. Retrieved 3 December 2011. "Ada, Go and Objective-C++ are not default languages"
17. ^ Gerrand, Andrew (1 February 2011). "release.2011-02-01". golang-nuts. Google. http://groups.google.com/group/golang-nuts/browse_thread/thread/b877e34723b543a7. Retrieved 5 February 2011.
18. ^ "A Tutorial for the Go Programming Language". The Go Programming Language. Google. http://golang.org/doc/go_tutorial.html. Retrieved 10 March 2010. "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."
19. ^ "A Tutorial for the Go Programming Language". golang.org. 16 January 2010. http://golang.org/doc/go_tutorial.html. Retrieved 18 January 2010.
20. ^ Simionato, Michele (15 November 2009). "Interfaces vs Inheritance (or, watch out for Go!)". artima. http://www.artima.com/weblogs/viewpost.jsp?thread=274019. Retrieved 15 November 2009.
21. ^ Astels, Dave (9 November 2009). "Ready, Set, Go!". engineyard. http://www.engineyard.com/blog/2009/ready-set-go/. Retrieved 9 November 2009.
22. ^ Paul, Ryan (10 November 2009). "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 13 November 2009.
23. ^ "TIOBE Programming Community Index for March 2012". TIOBE Software. March 2012. http://es.scribd.com/doc/89569304/TIOBE-Programming-Community-Index-for-March-2012. Retrieved 28 April 2012.
24. ^ Bruce Eckel (27). "Calling Go from Python via JSON-RPC". http://www.artima.com/weblogs/viewpost.jsp?thread=333589. Retrieved 29 August 2011.
25. ^ Claburn, Thomas (11 November 2009). "Google 'Go' Name Brings Accusations Of Evil'". InformationWeek. http://www.informationweek.com/news/software/web_services/showArticle.jhtml?articleID=221601351. Retrieved 18 January 2010.
26. ^ "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 12 October 2010.

## [edit] Further reading

- Chisnall, David (9 May 2012). "Common Go Patterns". The Go Programming Language Phrasebook. Addison-Wesley Professional. ISBN 0-321-81714-1. http://www.informit.com/articles/article.aspx?p=1760496.
- Summerfield, Mark (5 May 2012). Programming in Go: Creating Applications for the 21st Century. Addison-Wesley Professional. ISBN 0-321-77463-9. http://www.informit.com/store/product.aspx?isbn=0321774639.

## [edit] 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
- Wynn Netherland & Adam Stacoviak (27 November 2009). "Episode 0.0.3 - Google’s Go Programming Language". The Changelog (Podcast). http://thechangelog.com/post/259401776/episode-0-0-3-googles-go-programming-language. — 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
- Steve Dalton (22 January 2011). "Episode 20 (Interview with Andrew Gerrand about Go Programming Language)". Coding By Numbers (Podcast). http://www.codingbynumbers.com/2011/01/coding-by-numbers-episode-20-interview.html.
- Schuster, Werner (25 February 2011). "Rob Pike on Google Go: Concurrency, Type System, Memory Management and GC". InfoQ. GOTO Conference: C4Media Inc.. http://www.infoq.com/interviews/pike-google-go.

Google Inc.
Co-founder & CEO Larry Page Executive Chairman Eric Schmidt Co-founder Sergey Brin Other directors John Doerr John L. Hennessy Ann Mather Paul Otellini Ram Shriram Shirley M. Tilghman Senior Advisor Al Gore Rajen Sheth
Advertising | Ad Manager AdMob Adscape AdSense Advertising Professionals AdWords Analytics Checkout DoubleClick Offers Wallet
Communication | Alerts Calendar Cloud Connect Contacts Friend Connect Gmail history interface Google+ Groups Talk Latitude Orkut Q & A Reader Sync Translate Voice
Software | Chrome Chrome Web Store Chrome OS Chromebook Cloud Print Currents Earth Sky Moon Mars Gadgets Goggles IME Pinyin Japanese Picasa Refine SketchUp Talk Toolbar Updater Urchin
Platforms | Account Android Google TV Google Nexus App Engine Apps Marketplace Authenticator BigTable Body Books Play Caja Google Compute Engine Project Glass Custom Search Dart Earth Engine Go GFS Native Client OpenSocial Public DNS Wallet Wave
Development tools | AJAX APIs App Inventor AtGoogleTalks Closure Tools Code Gadgets API GData Googlebot Guice GWS KML MapReduce SketchUp Ruby Sitemaps Summer of Code Web Toolkit Website Optimizer Swiffy
Publishing | Google 3D Warehouse Blogger Bookmarks Docs Drive FeedBurner iGoogle Knol Map Maker Panoramio Picasa Web Albums Sites (JotSpot) YouTube Zagat
Search (PageRank) | Appliance Audio Books Library Project eBooks Finance Images Maps Street View Timeline Privacy concerns Competition Locations News Patents Scholar Shopping Usenet Videos Web Search History Personalized Real-Time Instant Search SafeSearch Analysis: Insights for Search Trends
Discontinued | Aardvark Answers Browser Sync Base Buzz Click-to-Call Code Search Desktop Dictionary Dodgeball Fast Flip Gears GOOG-411 Jaiku Health Image Labeler Labs Lively Mashup Editor Notebook Pack Page Creator Picnik PowerMeter SearchWiki Sidewiki Slide Google Squared Video Marketplace Wave Web Accelerator Google X
Related | Acquisitions AI Challenge Art Project Bomb Criticism Domains Driverless car Fiber Foundation Google China Googlization Grants Google.org Googleplex History Hoaxes I'm Feeling Lucky I/O Logo 1998–2009 2010 2011 2012 Lunar X Prize Monopoly City Streets Motorola Mobility Products Science Fair Searchology Unity Ventures WiFi Data Liberation
History of Google Motto: Don't be evil

Rob Pike
Operating systems | Plan 9 from Bell Labs Inferno
Programming languages | Newsqueak Limbo Go Sawzall
Software | acme Blit sam rio 8½
Publications | The Practice of Programming The Unix Programming Environment
Other | Renée French Mark V Shaney UTF-8

Ken Thompson
Operating systems | Unix Plan 9 from Bell Labs
Programming languages | B Bon Go
Software | Belle ed sam Space Travel
Other | UTF-8

Retrieved from "http://en.wikipedia.org/w/index.php?title=Go_(programming_language)&oldid=508833010"
Categories:

- C programming language family
- Concurrent programming languages
- Google software
- Procedural programming languages
- Systems programming languages
- Cross-platform software
- Programming languages created in 2009
- American inventions

Hidden categories:

- Wikipedia introduction cleanup from March 2012
- All pages needing cleanup
- Articles covered by WikiProject Wikify from March 2012
- All articles covered by WikiProject Wikify
- All articles with unsourced statements
- Articles with unsourced statements from May 2012
- Articles containing potentially dated statements from March 2012
- All articles containing potentially dated statements
- Use dmy dates from August 2011

##### Personal tools

- Create account
- Log in

##### Interaction

- Help
- About Wikipedia
- Community portal
- Recent changes
- Contact Wikipedia

##### Toolbox

- What links here
- Related changes
- Upload file
- Special pages
- Permanent link
- Cite this page

##### Print/export

- Create a book
- Download as PDF
- Printable version

##### Languages

- العربية
- Български
- Česky
- Dansk
- Deutsch
- Español
- Français
- 한국어
- Italiano
- עברית
- Magyar
- Bahasa Melayu
- Nederlands
- 日本語
- ‪norsk (bokmål)‬
- Polski
- Português
- Русский
- Српски / srpski
- Suomi
- Svenska
- தமிழ்
- Türkçe
- Українська
- Tiếng Việt
- 中文