CSC/ECE 517 Fall 2014/ch1a 10 hu
Go, also commonly referred to as golang, is a compiled, concurrent, garbage-collected, statically typed language developed at Google[1]. It was developed by Robert Griesemer[2], Rob Pike[3] and Ken Thompson[4] in 2007. It was announced in November 2009 and is currently being used in many production systems at Google. It is an open source project. The syntax is loosely derived from that of C programming language, adding garbage collection, type safety, some dynamic-typing capabilities. Additional built-in types such as variable-length arrays and key-value maps, and a large standard library are also supported. Go's "gc" compiler targets the Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Plan 9, and Microsoft Windows operating systems and the i386, amd64, and ARM processor architectures.
Background
Go programming started of as a research project by Robert Griesemer, Rob Pike and Ken Thompson. In the last decade before 2008, there was no new systems language , while there were quite lot of other developments like increase in the size of libraries, dominance of networking , client server focus, multi-core CPUs. So they wanted to come up with a new Systems language as the other current languages did not address the above issues. They started sketching the goals for a new language on the white board on September 21, 2007. Within a few days the goals had settled into a plan to do something and a fair idea of what it would be. Design continued part-time in parallel with unrelated work. By January 2008, Ken had started work on a compiler with which to explore ideas; it generated C code as its output. By mid-year the language had become a full-time project and had settled enough to attempt a production compiler. In May 2008, Ian Taylor independently started on a GCC front end for Go using the draft specification. Russ Cox joined in late 2008 and helped move the language and libraries from prototype to reality. Go became a public open source project on November 10, 2009. Many people from the community have contributed ideas, discussions, and code.
Go Compilers
There are two Go compiler implementations, gc (the 6g program and friends) and gccgo. Gc uses a different calling convention and linker and can therefore only be linked with C programs using the same convention. There is such a C compiler but no C++ compiler. Gccgo is a GCC front-end that can, with care, be linked with GCC-compiled C or C++ programs. The cgo program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries.
Runtime support for Go
Again due to bootstrapping issues, the run-time code is mostly in C (with a tiny bit of assembler) although Go is capable of implementing most of it now. Gccgo's run-time support uses glibc. Gc uses a custom library to keep the footprint under control; it is compiled with a version of the Plan 9 C compiler that supports resizable stacks for goroutines. The gccgo compiler implements these on Linux only, using a technique called segmented stacks, supported by recent modifications to the gold linker.
Language Design
Syntax
package main //line 1 import “fmt” //line 2 func main() { //line 3 fmt.Println(“Hello World”) //line 4 } //line 5
Code conventions and Style
Types
Variables and Constants
Control Structures
Arrays, Slices and Maps
Functions
Pointers
Concurrency
Applications
where it is currently being used Write stuff from the actual wiki page . It can be used to develop a server
Users of Go
Apart from Google, which uses Go programming for some of its development, companies like Dropbox, CloudFlare, SoundCloud, The BBC, Novartis, Cloud Foundry also use Go programming. Dropbox server (running in the cloud) and desktop client software were primarily written in Python. From mid-2013 Dropbox began migrating its backend infrastructure to Go. Some of the open-source applications that are using Go programming are Docker, Flynn, PaaS, Juju, nsq, Doozer e.t.c
Advantages
C Level Performance -- golang is within a close margin of the performance level of C code (which is itself an extremely high performance language). It is certainly closer to the performance of native languages than other enterprise level languages such as Java, Scala, Erlang etc. Illustration Reduced compile time is a key improvement in the Go language If A.go depends on B.go depends on C.go : · Compile C.go, B.go then A.go normally(other languages) · To compile A.go, compiler reads B.o not C.o · At a large scale this should help in hugely speeding up
· Fast Compilation -- The Golang compiler was designed to compile programs very quickly. Extremely large programs with massively high LOC counts compile seemingly instantly - afterall, Golang was designed by Google to solve Google problems, and Google has big problems! At Google, code and CPU cores are both measured in the millions. Go provides a model for software construction that makes dependency analysis easy and avoids much of the overhead of C-style include files and libraries. · Concurrency Supported At Language Level -- Concurrency is the ability to execute multiple computations simultaneuously. In today's modern multicore and high-load computing environment, concurrency is a critical language feature, and one in which languages such as Java struggle immensely. · By its design, Go proposes an approach for the construction of system software on multicore machines. · Google have summed things up nicely with their motto: "Don't communicate by sharing memory, share memory by communicating. "Go's type system has no hierarchy, so no time is spent defining the relationships between types. Also, although Go has static types the language attempts to make types feel lighter weight than in typical OO languages. · Garbage Collection -- In C and C++, programmers spend a lot of time and energy on allocating and freeing memory. The designers of Go wanted to remove that complication, and ensure Go programmers could concentrate on more productive tasks. As such, they implemented garbage collection. As a developer, this is a very good thing. Sure, garbage collection comes with its own set of issues, but those are dealt with by the language implementer while the programmer is free to reap the other many benefits of Go.
Limitations
· Go is still an experimental language subject to change. · Go's not very usable on Windows yet. · The packages distributed with Go are pretty useful, but there are still some libraries you'll miss. Most notably a UI toolkit. · There is no support for generics in Go, although there are many discussions around it.
Design Principles
Programming today involves too much bookkeeping, repetition, and clerical work. As Dick Gabriel says, “Old programs read like quiet conversations between a well-spoken research worker and a well-studied mechanical colleague, not as a debate with a compiler. Who'd have guessed sophistication bought such noise?” The sophistication is worthwhile—no one wants to go back to the old languages—but can it be more quietly achieved?
Go attempts to reduce the amount of typing in both senses of the word. Throughout its design, we have tried to reduce clutter and complexity. There are no forward declarations and no header files; everything is declared exactly once. Initialization is expressive, automatic, and easy to use. Syntax is clean and light on keywords. Stuttering (foo.Foo* myFoo = new(foo.Foo)) is reduced by simple type derivation using the := declare-and-initialize construct. And perhaps most radically, there is no type hierarchy: types just are, they don't have to announce their relationships. These simplifications allow Go to be expressive yet comprehensible without sacrificing, well, sophistication.
Another important principle is to keep the concepts orthogonal. Methods can be implemented for any type; structures represent data while interfaces represent abstraction; and so on. Orthogonality makes it easier to understand what happens when things combine.