Jump to content

Go (programming language): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Reverted edits by 192.54.45.83 (talk) to last version by Hydrox
Undid revision 348938612 by Cybercobra (talk)
Line 46: Line 46:
import "fmt"
import "fmt"


func main() {
func main()
{
fmt.Printf("Hello, World\n")
fmt.Printf("Hello, World\n")
}
}

Revision as of 12:19, 10 March 2010

Go
Paradigmcompiled, concurrent, imperative, structured
Designed byRobert Griesemer
Rob Pike
Ken Thompson
Google Inc.
DeveloperGoogle Inc.
First appeared2009
Typing disciplinestrong
OSLinux, Mac OS X, others[1]
LicenseBSD
Websitegolang.org
Major implementations
gc (8g, 6g), gccgo
Influenced by
C, Oberon, Limbo[2]

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,[2] 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] As of the launch, Go was not considered to be ready for adoption in production environments.[6]

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.[7] The language requires garbage collection. Certain concurrency-related structural conventions of Go (channels and alternative channel inputs) are borrowed from Tony Hoare's CSP, but many (such as Edsger Dijkstra's guarded commands) are omitted. Unlike previous concurrent programming languages such as occam or Limbo, Go does not provide any in-built notion of safe or verifiable concurrency [8]. Go also has some features of the Pi calculus such as channel passing.

Features not included in Go are exception handling, type inheritance, generic programming, assertions, and method overloading and pointer arithmetic.[2] Of these, the Go authors express an openness to generic programming and exceptions, explicitly argue against assertions and pointer arithmetic, while defending the choice to omit type inheritance on efficiency grounds.[2] Unlike Java, 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.

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.[9] Both compilers only work on Unix-like systems, although a Windows version available for non-production use is located here; it is maintained by a developer named Hector Chu[10] separate from the Go language team.[11] There is also a Go version available for Cygwin.

Examples

The following is a Hello world program in Go.

package main

import "fmt"

func main()
{
	fmt.Printf("Hello, World\n")
}

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

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.

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

Mark C. Chu-Carroll writes "So... At the end of the day, what do I think? I like Go, but I don't love it. If it had generics, it would definitely be my favorite of the C/C++/C#/Java family. It's got a very elegant simplicity to it which I really like. The interface type system is wonderful. The overall structure of programs and modules is excellent. But it's got some ugliness. Some of the ugliness is fixable, and some of it isn't. On balance, I think it's a really good language, but it could have been a lot better. It's not going to wipe C++ off the face of the earth. But I think it will establish itself as a solid alternative. And hopefully, over time, they'll fix some of the worst parts of the ugliness, without sacrificing the beauty or simplicity of the language."[14]

Dave Astels at Engine Yard writes "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."[15]

Blogger Michael Hoisie writes "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)."[16]

A blog posting in InformationWeek considers the creation of a new language to be unjustified given that many other languages already existed: "I don't have anything against a programming language devised experimentally (...) but what's the experiment?".[17] He expresses the belief that the major problem facing developers is the difficulty of writing code that runs on platforms like browsers which are not compatible with each other.

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]

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.[18] As of 16 December 2009, Google has not commented on the issue, although they let InformationWeek know that they were aware of it.

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.

See also

References

This article incorporates material from the official Go tutorial, which is licensed under the Creative Commons Attribution 3.0 license.
  1. ^ "Go Porting Efforts". Go Language Resources. cat-v. 2010-01-12. Retrieved 2010-01-18.
  2. ^ a b c d "Language Design FAQ". golang.org. 2010-01-16. Retrieved 2010-01-18.
  3. ^ Kincaid, Jason (2009-11-10). "Google's Go: A New Programming Language That's Python Meets C++". TechCrunch. Retrieved 2010-01-18.
  4. ^ "Source file src/cmd/goyacc/goyacc.go". golang.org. 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. Retrieved 2010-01-18.
  6. ^ a b Paul, Ryan (2009-11-10). "Go: new open source programming language from Google". Ars Technica. Retrieved 2009-11-13.
  7. ^ Rob Pike (2009-11-10). The Go Programming Language (flv) (Tech talk). Google. Event occurs at 8:53.
  8. ^ "The Go Memory Model". Google. 23 Februari 2010. {{cite web}}: Check date values in: |date= (help)
  9. ^ "FAQ: Implementation". golang.org. 2010-01-16. Retrieved 2010-01-18.
  10. ^ "Download initial Windows port of go here". golang-nuts. Google. 2009-11-23. Retrieved 2010-01-18.
  11. ^ "Issue 107: Windows support for Go". Go issue tracker. Retrieved 2010-01-18.
  12. ^ "A Tutorial for the Go Programming Language". golang.org. 2010-01-16. Retrieved 2010-01-18.
  13. ^ Simionato, Michele (2009-11-15). "Interfaces vs Inheritance (or, watch out for Go!)". artima. Retrieved 2009-11-15.
  14. ^ Chu-Carroll, Mark (2009-11-11). "Google's New Language: Go". Scienceblogs. Retrieved 2009-11-11.
  15. ^ Astels, Dave (2009-11-9). "Ready, Set, Go!". engineyard. Retrieved 2009-11-9. {{cite news}}: Check date values in: |accessdate= and |date= (help)
  16. ^ Hoisie, Michael (2009-11-11). "My thoughts on the Go Programming language". hoisie dot com. Retrieved 2009-11-11.
  17. ^ Yegulalp, Serdar (2009-11-12). "Why Google's Go Might Be A No-Go". InformationWeek. Retrieved 2009-11-13.
  18. ^ Claburn, Thomas (2009-11-11). "Google 'Go' Name Brings Accusations Of 'Evil'". InformationWeek. Retrieved 2010-01-18.