Welcome to our website. It is generaly simplier version of wikipedia. You will find there selected articles. Enjoy!
|
|
This article's lead section may not adequately summarize its contents. Please consider expanding the lead to provide an accessible overview of the article's key points. (March 2012) |
Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.
The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being used "for real stuff" at Google. 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.
Contents |
Go aims to provide the efficiency of a statically typed compiled language with the ease of programming of a dynamic language. Other goals include:
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 explicit; and new go and select control keywords have been introduced to support concurrent programming. New built-in types include maps, Unicode strings, array slices, and channels for inter-thread communication.
Go is designed for exceptionally fast compiling times, even on modest hardware. 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.
Of features found in C++ or Java, Go does not include type inheritance, generic programming, assertions, method overloading, or pointer arithmetic. 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. 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.
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.
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.
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.
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.
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.
There are currently two Go compilers:
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.
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.
Example illustrating how to write a program like the Unix echo command in Go:
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) }
Go's initial release led to much discussion.
David Given compared it unfavorably to another programming language he called "Brand X", which was finally revealed to be Algol 68, commenting that this showed an overall lack of progress in procedural programming language design over the course of the intervening 41 years.
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 :-(
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.
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. ... [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 in its first year, 2009, surpassing established languages like Pascal. As of March 2012, it ranked 66th in the index.
Bruce Eckel stated:
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.
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. While McCabe has not trademarked the name, some commenters on McCabe's request called for Google to adopt a new one. 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."
|
|||||||||||||||||||||||||||||||||||
|
|||||||||||||||||
|
||||||||||||||