Go (programming language)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Go
Golang.png
Paradigm compiled, concurrent, imperative, structured, statically typed
Appeared in 2009
Designed by Robert Griesemer
Rob Pike
Ken Thompson
Developer Google Inc.
Typing discipline strong
Major implementations gc (8g, 6g), gccgo
Influenced by C, Limbo, Modula, Newsqueak, Oberon, Pascal[1]
OS Linux, Mac OS X, others in progress or in planning[2]
License BSD
Website golang.org

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

The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson,[1] building on previous work related to the Inferno operating system.[4] Go was officially announced in November 2009, with implementations released for the Linux and Mac OS X platforms.[5] At the time of its launch, Go was not considered to be ready for adoption in production environments.[6] In May 2010, Rob Pike stated publicly that Go is being used "for real stuff" at Google.[7]

Contents

[edit] Description

The syntax of Go is close to that of C except for the type declarations; other syntactical differences are the missing parentheses around for and if expressions. It is designed for exceptionally fast compilation times, even on modest hardware.[8] 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 in-built notion of safe or verifiable concurrency.[9] Today, Go does not have any kind of built-in generics implementation, but one may be added in the future.[10]

Features not included in Go are type inheritance, generic programming, assertions, method overloading, and pointer arithmetic.[1] 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.[1] Initially, the language did not include exception handling, but this was added in March 2010.[11][12] Maps (also known as hashes or dictionaries) are an intrinsic part of the language, as are strings.

Visibility of functions outside of their defining file is defined implicitly according to the capitalization of their identifier, in contrast to C, where an explicit static keyword is used.[13]

[edit] Implementations

There are currently two Go compilers. 6g (and its supporting tools, collectively known as gc) are in C, using yacc/Bison for the parser. Gccgo is a Go compiler with a C++ front-end with a recursive descent parser coupled to the standard GCC backend.[14] Both compilers only work on Unix-like systems, although a Windows version for non-production use is available;[15] it is maintained by a developer named Hector Chu[16] separate from the Go language team.[17] There is also a Go version available for Cygwin.[18] Recently, Windows ports based on mingw are being deployed and updated.[19]

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

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

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: "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 :-("[22]

Dave Astels at Engine Yard wrote: "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."[23]

Blogger Michael Hoisie wrote: "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)."[24]

Ars Technica interviewed Rob Pike, one of the authors of Go, and asked why a new language was needed. He replied that "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." They did not want however "to deviate too much from what developers already knew because they wanted to avoid alienating Go's target audience."[6]

[edit] Naming dispute

On the day of the general release of the language, Francis McCabe, developer of the Go! programming language, requested a name change of Google's language to prevent confusion with his language. While McCabe has not trademarked the name, commenters on McCabe's posting have called for Google to adopt a new one. As of 16 December 2009 (2009 -12-16), Google has not commented on the issue, although they let InformationWeek know that they were aware of it.[25]

[edit] Concurrency

Go provides goroutines, small lightweight threads; the name alludes to coroutines. Goroutines are created with the "go" statement from anonymous or normal 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] Popularity

Go entered the TIOBE Programming Community Index[26] at fifteenth place in its first year, surpassing established languages like Pascal. But as of June 2010, it has dropped out of the top 20. As of 1 August 2010 (2010 -08-01), it is in the 20th place.

[edit] See also

[edit] References

This article incorporates material from the official Go tutorial, which is licensed under the Creative Commons Attribution 3.0 license.
  1. ^ a b c d "Language Design FAQ". golang.org. 2010-01-16. http://golang.org/doc/go_lang_faq.html. Retrieved 2010-01-18. 
  2. ^ "Go Porting Efforts". Go Language Resources. cat-v. 2010-01-12. http://go-lang.cat-v.org/os-ports. Retrieved 2010-01-18. 
  3. ^ 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. 
  4. ^ "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"
     
  5. ^ "Installing Go". golang.org. 2010-01-14. http://golang.org/doc/install.html#tmp_33. Retrieved 2010-01-18. 
  6. ^ a b 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. 
  7. ^ "Google programming Frankenstein is a Go". The Register. 20 May 2010. http://www.theregister.co.uk/2010/05/20/go_in_production_at_google/. 
  8. ^ 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. 
  9. ^ "The Go Memory Model". Google. 23 Februari 2010. http://golang.org/doc/go_mem.html. 
  10. ^ Discussion about generics in Go, golang-nuts, 18 Dec 2009, http://groups.google.com/group/golang-nuts/browse_thread/thread/801e9412de89baab/1a6e791e2dbf096b?q=generics&lnk=ol& 
  11. ^ Release notes, 3/30/2010
  12. ^ "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. 
  13. ^ "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." 
  14. ^ "FAQ: Implementation". golang.org. 2010-01-16. http://golang.org/doc/go_faq.html#Implementation. Retrieved 2010-01-18. 
  15. ^ http://code.google.com/p/go-windows/
  16. ^ "Download initial Windows port of go here". golang-nuts. Google. 2009-11-23. http://groups.google.com/group/golang-nuts/browse_thread/thread/b42b70700575d7bb. Retrieved 2010-01-18. 
  17. ^ "Issue 107: Windows support for Go". Go issue tracker. http://code.google.com/p/go/issues/detail?id=107. Retrieved 2010-01-18. 
  18. ^ http://code.google.com/p/golang-on-cygwin/
  19. ^ http://code.google.com/p/gomingw/
  20. ^ "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." 
  21. ^ "A Tutorial for the Go Programming Language". golang.org. 2010-01-16. http://golang.org/doc/go_tutorial.html. Retrieved 2010-01-18. 
  22. ^ 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. 
  23. ^ Astels, Dave (2009-11-09). "Ready, Set, Go!". engineyard. http://www.engineyard.com/blog/2009/ready-set-go/. Retrieved 2009-11-09. 
  24. ^ 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. 
  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. 
  26. ^ "TIOBE Programming Community Index". http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html. 

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages