Jump to content

Go (programming language)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 91.213.255.7 (talk) at 18:20, 3 December 2011 (How it is not standars as it is included in 4.6.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Template:Distinguish2

Go
Paradigmcompiled, concurrent, imperative, structured
Designed byRobert Griesemer
Rob Pike
Ken Thompson
DeveloperGoogle Inc.
First appeared2009
Stable release
r60[1] / September 7, 2011; 12 years ago (2011-09-07)
Typing disciplinestrong, static
OSLinux, Mac OS X, FreeBSD, OpenBSD, MS Windows, Plan 9[2]
LicenseBSD-style[3]
Filename extensions.go
Websitegolang.org
Major implementations
gc (8g, 6g, 5g), gccgo
Influenced by
C, Limbo, Modula, Newsqueak, Oberon, Pascal[4]

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.[4] Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being used "for real stuff" at Google.[6] Go's "gc" compiler targets the Linux, Mac OS X, FreeBSD, OpenBSD and Microsoft Windows operating systems and the i386, amd64, and ARM processor architectures.[7]

Goals

Go aims to provide the efficiency of a statically-typed compiled language with the ease of programming of a dynamic language.[8] 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 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.[9] 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.[10]

Of features found in C++ or Java, Go does not include type inheritance, generic programming, assertions, method overloading, or pointer arithmetic.[4] 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.[4] 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.[11][12]

Go interfaces do not participate in a type hierarchy like Java's. They are better described as a set of methods, identified by their name and signature. An interface can be declared to embed other interfaces, meaning the declared interface borrows the methods defined in the other interfaces, making them part of the set of methods of the declared interface [10]. A type matches an interface if it defines the methods (same name and same signature) from this interface.

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

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++,[14] and now officially supported as of version 4.6.

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

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

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

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

Michele Simionato wrote in an article for artima.com:[19]

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:[20]

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:[21]

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:[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 entered the TIOBE Programming Community Index at fifteenth place in its first year,[23] surpassing established languages like Pascal. As of 11 September 2011, it ranked 32nd in the index.[24]

Bruce Eckel stated:[25]

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.

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.[26] While McCabe has not trademarked the name, some commenters on McCabe's request called for Google to adopt a new one. However, contradicting established practice of eliminating name clashes (frequently resorting to court), 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."[27]

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.

  1. ^ "Release History - The Go Programming Language". Retrieved 8 September 2011.
  2. ^ "Go Porting Efforts". Go Language Resources. cat-v. 12 January 2010. Retrieved 18 January 2010.
  3. ^ "Text file LICENSE". Retrieved 27 January 2011.
  4. ^ a b c d "Language Design FAQ". golang.org. 16 January 2010. Retrieved 27 February 2010.
  5. ^ Kincaid, Jason (10 November 2009). "Google's Go: A New Programming Language That's Python Meets C++". TechCrunch. Retrieved 18 January 2010.
  6. ^ Metz, Cade (20 May 2010). "Google programming Frankenstein is a Go". The Register.
  7. ^ "Installing Go". golang.org. The Go Authors. 11 June 2010. Retrieved 11 June 2010.
  8. ^ Pike, Rob. "The Go Programming Language". YouTube. Retrieved 1 July 2011.
  9. ^ Rob Pike (10 November 2009). The Go Programming Language (flv) (Tech talk). Google. Event occurs at 8:53.
  10. ^ a b "The Go Memory Model". Google. Retrieved 5 January 2011. Cite error: The named reference "memmodel" was defined multiple times with different content (see the help page).
  11. ^ Release notes, 30 March 2010
  12. ^ "Proposal for an exception-like mechanism". golang-nuts. 25 March 2010. Retrieved 25 March 2010.
  13. ^ "A Tutorial for the Go Programming Language". The Go Programming Language. Google. 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.
  14. ^ "FAQ: Implementation". golang.org. 16 January 2010. Retrieved 18 January 2010.
  15. ^ Gerrand, Andrew (1 February 2011). "release.2011-02-01". golang-nuts. Google. Retrieved 5 February 2011.
  16. ^ "A Tutorial for the Go Programming Language". The Go Programming Language. Google. 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.
  17. ^ "A Tutorial for the Go Programming Language". golang.org. 16 January 2010. Retrieved 18 January 2010.
  18. ^ Given, David (15 November 2009). "On Go". Retrieved 29 March 2011.
  19. ^ Simionato, Michele (15 November 2009). "Interfaces vs Inheritance (or, watch out for Go!)". artima. Retrieved 15 November 2009.
  20. ^ Astels, Dave (9 November 2009). "Ready, Set, Go!". engineyard. Retrieved 9 November 2009.
  21. ^ Hoisie, Michael (11 November 2009). "My thoughts on the Go Programming language". hoisie dot com. Retrieved 11 November 2009.
  22. ^ Paul, Ryan (10 November 2009). "Go: new open source programming language from Google". Ars Technica. Retrieved 13 November 2009.
  23. ^ The major TIOBE 2009 language is Go
  24. ^ "TIOBE Programming Community Index for September 2011". TIOBE Software. September 2011. Retrieved 11 September 2011.
  25. ^ Bruce Eckel (27). "Calling Go from Python via JSON-RPC". Retrieved August 29, 2011. {{cite web}}: Check date values in: |date= and |year= / |date= mismatch (help); Unknown parameter |month= ignored (help)
  26. ^ Claburn, Thomas (11 November 2009). "Google 'Go' Name Brings Accusations Of Evil'". InformationWeek. Retrieved 18 January 2010.
  27. ^ "Issue 9 - go - I have already used the name for *MY* programming language". Google Code. Google Inc. Retrieved 12 October 2010.

External links