Tuesday, August 17, 2010

Go (programming language)

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]

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)[update], 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[update], it has dropped out of the top 20. As of 1 August 2010 (2010 -08-01)[update], it is in the 20th place.

No comments:

Post a Comment