Jump to content

Go (programming language): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m use last names
Reception: Edited and added citations for Go's rise in popularity on the TIOBE index
Line 160: Line 160:
{{quote |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.}}
{{quote |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 in 15th place on the [[TIOBE Programming Community Index]] of programming language popularity in its first year, 2009,{{cn|date=May 2012}} surpassing established languages like [[Pascal (programming language)|Pascal]]. {{As of|2012|3|}}, it ranked 66th in the index.<ref>{{cite web |url=http://es.scribd.com/doc/89569304/TIOBE-Programming-Community-Index-for-March-2012 |title=TIOBE Programming Community Index for March 2012 |date=March 2012 |publisher=TIOBE Software |accessdate=28 April 2012}}</ref>
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 of 2010<ref>{{cite web|first=jt|title=Google's Go Wins Programming Language Of The Year Award|url=http://jaxenter.com/google-s-go-wins-programming-language-of-the-year-award-10069.html|publisher=jaxenter|accessdate=5 December 2012}}</ref>, surpassing established languages like [[Pascal (programming language)|Pascal]]. {{As of|2012|3|}}, it ranked 66th in the index.<ref>{{cite web |url=http://es.scribd.com/doc/89569304/TIOBE-Programming-Community-Index-for-March-2012 |title=TIOBE Programming Community Index for March 2012 |date=March 2012 |publisher=TIOBE Software |accessdate=28 April 2012}}</ref>


[[Bruce Eckel]] stated:<ref>{{cite web |url=http://www.artima.com/weblogs/viewpost.jsp?thread=333589 |title=Calling Go from Python via JSON-RPC |date=27 |month=August |year=2011 |author=Bruce Eckel |accessdate=29 August 2011}}</ref>
[[Bruce Eckel]] stated:<ref>{{cite web |url=http://www.artima.com/weblogs/viewpost.jsp?thread=333589 |title=Calling Go from Python via JSON-RPC |date=27 |month=August |year=2011 |author=Bruce Eckel |accessdate=29 August 2011}}</ref>

Revision as of 20:59, 5 December 2012


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 is a compiled, garbage-collected, concurrent programming language developed by Google Inc.[6]

The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.[5] Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being used "for real stuff" at Google.[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.
  • 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 explicitly, and new go and select control keywords have been introduced to support concurrent programming. New built-in types include maps, UTF-8 strings, array slices, and channels for inter-thread communication.

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

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

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

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

Consider the following example:

type Sequence []int

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

type HasLength interface {
    Len() int
}

func Foo (o HasLength) {
    ...
}

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

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

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.

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++,[16] and now officially supported as of version 4.6, albeit not part of the standard binary for gcc.[17]

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

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

Echo

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

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

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

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

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 of 2010[24], surpassing established languages like Pascal. As of March 2012, it ranked 66th in the index.[25]

Bruce Eckel stated:[26]

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.[27] The issue was closed by a Google developer on 12 October 2010 with the custom status "Unfortunate", with a comment 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."[28]

See also

References

  1. ^ Gerrand, Andrew (24 September 2012). "go1.0.3 released". golang-announce (Mailing list). Google. Retrieved 05 October 2012. {{cite mailing list}}: Check date values in: |accessdate= (help); 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 05 October 2012. {{cite web}}: Check date values in: |accessdate= (help)
  4. ^ "Additional IP Rights Grant". The Go Programming Language. Google. Retrieved 05 October 2012. {{cite web}}: Check date values in: |accessdate= (help)
  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. ^ Metz, Cade (20 May 2010). "Google programming Frankenstein is a Go". The Register.
  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. ^ Rob Pike (10 November 2009). The Go Programming Language (flv) (Tech talk). Google. Event occurs at 8:53.
  11. ^ 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).
  12. ^ Release notes, 30 March 2010
  13. ^ "Proposal for an exception-like mechanism". golang-nuts. 25 March 2010. Retrieved 25 March 2010.
  14. ^ "Go Data Structures: Interfaces". Retrieved 15 November 2012.
  15. ^ "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.
  16. ^ "FAQ: Implementation". golang.org. 16 January 2010. Retrieved 18 January 2010.
  17. ^ "Installing GCC: Configuration". Retrieved 3 December 2011. Ada, Go and Objective-C++ are not default languages
  18. ^ Gerrand, Andrew (1 February 2011). "release.2011-02-01". golang-nuts. Google. Retrieved 5 February 2011.
  19. ^ "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.
  20. ^ "A Tutorial for the Go Programming Language". golang.org. 16 January 2010. Retrieved 18 January 2010.
  21. ^ Simionato, Michele (15 November 2009). "Interfaces vs Inheritance (or, watch out for Go!)". artima. Retrieved 15 November 2009.
  22. ^ Astels, Dave (9 November 2009). "Ready, Set, Go!". engineyard. Retrieved 9 November 2009.
  23. ^ Paul, Ryan (10 November 2009). "Go: new open source programming language from Google". Ars Technica. Retrieved 13 November 2009.
  24. ^ "Google's Go Wins Programming Language Of The Year Award". jaxenter. Retrieved 5 December 2012. {{cite web}}: |first= missing |last= (help)
  25. ^ "TIOBE Programming Community Index for March 2012". TIOBE Software. March 2012. Retrieved 28 April 2012.
  26. ^ 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)
  27. ^ Claburn, Thomas (11 November 2009). "Google 'Go' Name Brings Accusations Of Evil'". InformationWeek. Retrieved 18 January 2010.
  28. ^ "Issue 9 - go - I have already used the name for *MY* programming language". Google Code. Google Inc. Retrieved 12 October 2010.

Further reading