Jump to content

Go (programming language): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Wei2912 (talk | contribs)
Add in Go's alternative name
Line 23: Line 23:
}}
}}


'''Go''' is a [[compiled language|compiled]], [[Garbage collection (computer science)|garbage-collected]], [[concurrent programming language|concurrent]] [[system programming language|system]] [[programming language]]. It was first designed and developed at [[Google|Google Inc.]]<ref>{{cite news|url=http://www.techcrunch.com/2009/11/10/google-go-language/|title=Google’s Go: A New Programming Language That’s Python Meets C++|last=Kincaid |first=Jason |date=10 November 2009 |newspaper=TechCrunch |accessdate=18 January 2010}}</ref> beginning in September 2007 by [[Robert Griesemer]], [[Rob Pike]], and [[Ken Thompson]].<ref name="langfaq">{{cite web|url=http://golang.org/doc/go_faq.html|title=Language Design FAQ|date=16 January 2010|work=golang.org|accessdate=27 February 2010}}</ref>
'''Go''', otherwise known as Golang, is a [[compiled language|compiled]], [[Garbage collection (computer science)|garbage-collected]], [[concurrent programming language|concurrent]] [[system programming language|system]] [[programming language]]. It was first designed and developed at [[Google|Google Inc.]]<ref>{{cite news|url=http://www.techcrunch.com/2009/11/10/google-go-language/|title=Google’s Go: A New Programming Language That’s Python Meets C++|last=Kincaid |first=Jason |date=10 November 2009 |newspaper=TechCrunch |accessdate=18 January 2010}}</ref> beginning in September 2007 by [[Robert Griesemer]], [[Rob Pike]], and [[Ken Thompson]].<ref name="langfaq">{{cite web|url=http://golang.org/doc/go_faq.html|title=Language Design FAQ|date=16 January 2010|work=golang.org|accessdate=27 February 2010}}</ref>


The language was officially announced in November 2009 and is now used in Google's production systems.<ref name="faq">{{cite news| url = http://golang.org/doc/faq#Is_Google_using_go_internally | title = Go FAQ: Is Google using Go internally? | accessdate = 9 March 2013}}</ref> Go's "gc" compiler targets the [[Linux]], [[Mac OS X]], [[FreeBSD]], [[OpenBSD]], [[Plan 9 from Bell Labs|Plan 9]], and [[Microsoft Windows]] operating systems and the [[i386]], [[amd64]], and [[ARM architecture|ARM]] processor architectures.<ref>{{cite web|url=http://golang.org/doc/install.html#tmp_33|title=Installing Go|date=11 June 2010|work=golang.org|publisher=The Go Authors|accessdate=11 June 2010}}</ref>
The language was officially announced in November 2009 and is now used in Google's production systems.<ref name="faq">{{cite news| url = http://golang.org/doc/faq#Is_Google_using_go_internally | title = Go FAQ: Is Google using Go internally? | accessdate = 9 March 2013}}</ref> Go's "gc" compiler targets the [[Linux]], [[Mac OS X]], [[FreeBSD]], [[OpenBSD]], [[Plan 9 from Bell Labs|Plan 9]], and [[Microsoft Windows]] operating systems and the [[i386]], [[amd64]], and [[ARM architecture|ARM]] processor architectures.<ref>{{cite web|url=http://golang.org/doc/install.html#tmp_33|title=Installing Go|date=11 June 2010|work=golang.org|publisher=The Go Authors|accessdate=11 June 2010}}</ref>

Revision as of 16:43, 20 April 2013

Template:Distinguish2

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

Go, otherwise known as Golang, is a compiled, garbage-collected, concurrent system programming language. It was first designed and developed at Google Inc.[6] beginning in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.[5]

The language was officially announced in November 2009 and is now used in Google's production systems.[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]

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.
  • Intuitive concurrency by providing "goroutines" and channels to communicate between them.
  • Efficient garbage collection "with low enough overhead and no significant latency".[10]
  • 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 explicitly, and new go and select control keywords have been introduced to support concurrent programming. New built-in types include maps, array slices, and channels for inter-thread communication.

Go is designed for exceptionally fast compiling times, even on modest hardware.[11] 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.[12]

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

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

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

Consider the following example:

type Sequence []int

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

type Sizer interface {
    Size() int
}

func Foo (o Sizer) {
    ...
}

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 Sizer, and the person who implemented the Size method for Sequence did not need to specify that this method was part of Sizer.

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. If the identifier starts with a capital letter, the identifier is visible from outside the package.[16]

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. Channels are bounded buffers, not network connections.

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 Thompson's previous work on Plan 9's C toolchain.
  • gccgo, a GCC frontend written in C++,[17] and now officially supported as of version 4.6, albeit not part of the standard binary for gcc.[18]

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

Examples

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

Echo

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

Reception

Go's initial release led to much discussion.

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

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

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

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 named Programming Language of the Year by the TIOBE Programming Community Index in its first year, 2009, for having a larger 12-month increase in popularity (in only 2 months, after its introduction in November) than any other language that year, and reached 13th place by January 2010,[25] surpassing established languages like Pascal. As of March 2012, it ranked 66th in the index.[26] Go is already in commercial use by several large organizations.[27]

Bruce Eckel stated:[28]

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.[29] The issue was closed by a Google developer on 12 October 2010 with the custom status "Unfortunate" and with the following comment: "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."[30]

See also

References

  1. ^ Gerrand, Andrew (24 September 2012). "go1.0.3 released". golang-announce (Mailing list). Google. Retrieved 5 October 2012. {{cite mailing list}}: Unknown parameter |mailinglist= ignored (|mailing-list= suggested) (help)
  2. ^ "Go Porting Efforts". Go Language Resources. cat-v. 12 January 2010. Retrieved 18 January 2010.
  3. ^ "Text file LICENSE". The Go Programming Language. Google. Retrieved 5 October 2012.
  4. ^ "Additional IP Rights Grant". The Go Programming Language. Google. Retrieved 5 October 2012.
  5. ^ a b c d "Language Design FAQ". golang.org. 16 January 2010. Retrieved 27 February 2010.
  6. ^ Kincaid, Jason (10 November 2009). "Google's Go: A New Programming Language That's Python Meets C++". TechCrunch. Retrieved 18 January 2010.
  7. ^ "Go FAQ: Is Google using Go internally?". Retrieved 9 March 2013.
  8. ^ "Installing Go". golang.org. The Go Authors. 11 June 2010. Retrieved 11 June 2010.
  9. ^ Pike, Rob. "The Go Programming Language". YouTube. Retrieved 1 July 2011.
  10. ^ "Why do garbage collection? Won't it be too expensive?". Retrieved 12 February 2013.
  11. ^ Rob Pike (10 November 2009). The Go Programming Language (flv) (Tech talk). Google. Event occurs at 8:53.
  12. ^ 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).
  13. ^ Release notes, 30 March 2010
  14. ^ "Proposal for an exception-like mechanism". golang-nuts. 25 March 2010. Retrieved 25 March 2010.
  15. ^ "Go Data Structures: Interfaces". Retrieved 15 November 2012.
  16. ^ "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.
  17. ^ "FAQ: Implementation". golang.org. 16 January 2010. Retrieved 18 January 2010.
  18. ^ "Installing GCC: Configuration". Retrieved 3 December 2011. Ada, Go and Objective-C++ are not default languages
  19. ^ Gerrand, Andrew (1 February 2011). "release.2011-02-01". golang-nuts. Google. Retrieved 5 February 2011.
  20. ^ "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.
  21. ^ "A Tutorial for the Go Programming Language". golang.org. 16 January 2010. Retrieved 18 January 2010.
  22. ^ Simionato, Michele (15 November 2009). "Interfaces vs Inheritance (or, watch out for Go!)". artima. Retrieved 15 November 2009.
  23. ^ Astels, Dave (9 November 2009). "Ready, Set, Go!". engineyard. Retrieved 9 November 2009.
  24. ^ Paul, Ryan (10 November 2009). "Go: new open source programming language from Google". Ars Technica. Retrieved 13 November 2009.
  25. ^ "Google's Go Wins Programming Language Of The Year Award". jaxenter. Retrieved 5 December 2012. {{cite web}}: |first= missing |last= (help)
  26. ^ "TIOBE Programming Community Index for March 2012". TIOBE Software. March 2012. Retrieved 28 April 2012.
  27. ^ "Google's Go Appears on Brazilian Cloud". Wired. 26 March 2013. Retrieved 28 March 2013.
  28. ^ Bruce Eckel (27). "Calling Go from Python via JSON-RPC". Retrieved 29 August 2011. {{cite web}}: Check date values in: |date= and |year= / |date= mismatch (help); Unknown parameter |month= ignored (help)
  29. ^ Claburn, Thomas (11 November 2009). "Google 'Go' Name Brings Accusations Of Evil'". InformationWeek. Retrieved 18 January 2010.
  30. ^ "Issue 9 - go - I have already used the name for *MY* programming language". Google Code. Google Inc. Retrieved 12 October 2010.