Go (often referred to as golang) is a programming language created at Google[ in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added. The compiler and other language tools originally developed by Google are all free and open source
The language was announced in November 2009. It is used in some of Google’s production systems, as well as by other firms.
Two major implementations exist:
- Google’s Go compiler, “gc”, developed as open-source software. It targets various platforms including Linux, OS X, Windows, various BSD and Unix versions, and also (since 2015) mobile devices (including smartphones).
- A second compiler, gccgo, is a GCC frontend.
The “gc” toolchain has been self-hosting since version 1.5.
Go originated as an experiment by Google engineers Robert Griesemer, Rob Pike, and Ken Thompson to design a new programming language that would resolve common criticisms of other languages while maintaining their positive characteristics. The developers envisaged the new language as:
- statically typed, scalable to large systems (as Java and C++)
- productive and readable, without too many mandatory keywords and repetition (“light on the page” like dynamic languages)
- not requiring integrated development environments, but supporting them well
- supporting networking and multiprocessing
In later interviews, all three of the language designers cited their shared dislike of C++’s complexity as a primary motivation for designing a new language.
Google released Go 1.0 in March 2012.
Go is recognizably in the tradition of C, but makes many changes to improve brevity, simplicity, and safety. Go consists of,
- A syntax and environment adopting patterns more common in dynamic languages:
- Optional concise variable declaration and initialization through type inference (x := 0 not int x = 0; or var x = 0;).
- Fast compilation times.
- Remote package management (go get) and online package documentation.
- Distinctive approaches to particular problems:
- Built-in concurrency primitives: light-weight processes (goroutines), channels, and the select statement.
- An interface system in place of virtual inheritance, and type embedding instead of non-virtual inheritance.
- A toolchain that, by default, produces statically linked native binaries without external dependencies.
- A desire to keep the language specification simple enough to hold in a programmer’s head, in part by omitting features common to similar languages.
Go’s syntax includes changes from C aimed at keeping code concise and readable. A combined declaration/initialization operator was introduced that allows the programmer to write i := 3 or s := “Hello, world!”, without specifying the types of variables. This contrasts with C’s int i = 3; and const char *s = “Hello, world!”;. Semicolons still terminate statements, but are implicit when the end of a line occurs. Functions may return multiple values, and returning a result, err pair is the conventional way a function indicates an error to its caller in Go. Go adds literal syntaxes for initializing struct parameters by name, and for initializing maps and slices. As an alternative to C’s three-statement for loop, Go’s range expressions allow concise iteration over arrays, slices, strings, maps, and channels.
Go has a number of built-in types, including numeric ones (byte, int64, float32, etc.), booleans, and character strings (string). Strings are immutable; built-in operators and keywords (rather than functions) provide concatenation, comparison, and UTF-8 encoding and decoding. Record types can be defined with the struct keyword.
For each type T and each non-negative integer constant n, there is an array type denoted [n]T; arrays of differing lengths are thus of different types. Dynamic arrays are available as “slices”, denoted T for some type T. These have a length and a capacity specifying when new memory needs to be allocated to expand the array. Several slices may share their underlying memory.
Pointers are available for all types, and the pointer-to-T type is denoted *T. Address-taking and indirection use the & and * operators as in C, or happen implicitly through the method call or attribute access syntax. There is no pointer arithmetic, except via the special unsafe.Pointer type in the standard library]
For a pair of types K, V, the type map[K]V is the type of hash tables mapping type-K keys to type-V values. Hash tables are built into the language, with special syntax and built-in functions. chan T is a channel that allows sending values of type T between concurrent Go processes.
Aside from its support for interfaces, Go’s type system is nominal: the type keyword can be used to define a new named type, which is distinct from other named types that have the same layout (in the case of a struct, the same members in the same order). Some conversions between types (e.g., between the various integer types) are pre-defined and adding a new type may define additional conversions, but conversions between named types must always be invoked explicitly. For example, the type keyword can be used to define a type for IPv4 addresses, which are 32-bit unsigned integers.
For more details or to start new programming projects please Contact Us.