GO PROGRAMMING LANGUAGE FROM GOOGLE full report
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
computer science topics
Active In SP
**

Posts: 610
Joined: Jun 2010
#1
29-06-2010, 12:33 PM



.docx   GO PROGRAMMING LANGUAGE FROM GOOGLE.docx (Size: 119.28 KB / Downloads: 244)

Presented By:
VISHWAS HANUMANT JADHAV
Under The Guidance of
Prof. Mr. NILESH PATNI
Modern College Of Engineering, Pune-05

Abstract

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, building on previous work related to the Inferno operating system. Go was officially announced in November 2009, with implementations released for the Linux and Mac OS X platforms.As of the launch, Go was not considered to be ready for adoption in production environments.
The syntax of Go is close to that of C except for the type declarations; other syntactical differences are the missing parentheses around for and if expressions. It is designed for exceptionally fast compilation 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, but many (such as Edsger Dijkstra's guarded commands) are omitted. Unlike previous concurrent programming languages such as occam or Limbo, Go does not provide any in-built notion of safe or verifiable concurrency. Go also has some features of the Pi calculus such as channel passing.
Features not included in Go are exception handling, type inheritance, generic programming, assertions, and method overloading and pointer arithmetic.Of these, the Go authors express an openness to generic programming and exceptions, explicitly argue against assertions and pointer arithmetic, while defending the choice to omit type inheritance on efficiency grounds. Unlike Java, maps (also known as hashes or dictionaries) are an intrinsic part of the language, as are strings.
Visibility of functions outside of their defining file is defined implicitly according to the capitalization of their identifier, in contrast to C, where an explicit static keyword is used.

1 INTRODUCTION
1.1 What Is Go Programming Language?

Go! is a logic programming descendant of the multi-threaded symbolic programming language April[25], with influences from IC-Prolog II [6] and _Alphabetical order of authors.
L&O[23]. Crudely. Go! is April enriched with the knowledge representation features of Prolog and L&O.
April was initially developed as the implementation language for the much higher level MAI2L[17] agent programming of the EU Imagine project and implimentation.It has more recently been used to implement one of the FIPA compliant agent platforms of the EU AgentCities project and implimentation[37], and the agent services running on that platform at Imperial College and Fujitsu. Go! was used as a query server using the language SL1, a subset of FIPA SL[13], for our AgentCities agents.
A significant theme in the design of Go! is software engineering in the service of high-integrity systems. To bring the benefits of logic programming to applications developers requires fitting the language into current bestpractice; and, especially since applications are increasingly operating in the Internet, security, transparency and integrity are critical to the adoption of logic programming technology. Although Go! has many features in common with Prolog, particularly multi-threaded Prologâ„¢s, there are significant differences related to transparency of code and security. Features of Prolog that mitigate against transparency, such as the infamous cut (!) primitive, are absent from Go!. Instead, its main uses are supported by higher level programming constructs, such as single solution calls, iff rules, and the ability to define â„¢functionalâ„¢ relations as functions.
In Prolog, the same clause syntax is used both for defining relations, with a declarative semantics, and for defining procedures, say that read and write to files, which really only have an operational semantics. In Go!, behaviours are described using action rules which have a different syntax. While Prolog is a meta-order language, Go! is higher-order as in higher order functional programming. Go! is not higher order in the higher order logic sense. There is no unification of function or relation definitions, as there is in lambda-Prolog[26]. Code can only be passed as an opaque value with a specific type.
A key feature of Go! is the ability to group a set of definitions into a lexical unit by surrounding them with {} braces. We call such a unit a theta environment. Theta environments are Go!â„¢s program structuring mechanism. Two key uses of theta environments are where expressions, analogous to the let ... in ... construct of some functional programming languages, and labeled theories, which are labeled theta environments. Labeled theories are based on McCabeâ„¢s L&O [23] extension of Prolog.
A labeled theory is theta environment labeled by a term where variables of the label term are global variables of the theory. Instances of the theory are created by giving values to these label variables. Labeled theories are analogous to class definitions, and their instances are Go!â„¢s objects. New labeled theories can be defined in terms of one or more existing theories using inheritance rules. Labeled theories provide a rich knowledge representation notation akin to that of frame systems[28].
Go! is strongly typed “ using a modified Hindley/Milner style type inference technique [18], [27] to reduce the programmer™s burden. The programmer can declare new types and thereby introduce new data constructors. Indeed, all uses of functors as data constructors need to be declared by being introduced in some type definition. Compile time type checking improves code safety.
Go! is also multi-threaded, a feature which we consider essential for building sophisticated agents. Threads primarily communicate through asynchronous message passing as in Erlang[1], April[25], Qu-Prolog[8]. Threads, executing action rules, react to received messages using pattern matching and pattern based message reaction rules. A communications daemon enables threads in different Go! processes to communicate transparently over a network. Typically, each agent will comprise several threads, each of which can directly communicate with threads in other agents.
Threads in the same Go! process, hence in the same agent, can also communicate by manipulating shared cell or dynamic relation objects. Updates of these objects are atomic. Moreover, threads can be made to suspend until a term unifying with some given term is added to a shared dynamic relation by some other thread. This enables dynamic relations to be used like Linda tuple stores[4] to coordinate the activities of different threads within an agent. This is a powerful implementation abstraction for building multi-threaded agents, which we will illustrate with our example application of Go!.
Go! does not directly support any specific agent architecture or agent programming methodology, although this could be done using library modules. It is a language is which different architectures and methodologies can be quickly prototyped and explored. We illustrate this by developing a simple multi-agent application comprising hybrid reactive/deliberative agents interacting at a simulated ball. In this ballroom there are male and female dancers. The dancers have desires that reflect “ somewhat “ a typical ballroom situation with the different desires corresponding to individual preferences. Dancers negotiate with each other over up-coming dances and also make counter proposals “ such as going to the bar instead of having a dance. Each dancer agent is programmed using multiple concurrently executing threads that implement different aspects of its behaviour.

1.2 Why Did Google Makes Its Own Language?

One of the core philosophies of Google, and one of the reasons it has been so successful, is efficiency. Itâ„¢s about both being as efficient as possible when serving search results and processing data and creating product that push the limits of efficiency for the user (as an example, Googleâ„¢s trying to make communication more efficient with Google Wave).
Maybe thatâ„¢s why weâ„¢re not surprised that Google is finally looking to tackle the underpinning code that runs the web. Today the search giant released Go, an open-source development language that Google believes will combine performance with speed, and one that the company probably hopes will reshape the development and software industries in its favor.
Go is based on the C programming family, one of the most widely used programming language trees in the world. However, the twist is that incorporates elements of Python (a preferred development language within Google) and the Pascal/Modula/Oberon family to make faster and more dynamic programs.
No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously. There are several trends:
- Computers are enormously quicker but software development is not faster.
- Dependency management is a big part of software development today but the header files of languages in the C tradition are antithetical to clean dependency analysis”and fast compilation.
- There is a growing rebellion against cumbersome type systems like those of Java and C++, pushing people towards dynamically typed languages such as Python and JavaScript.
- Some fundamental concepts such as garbage collection and parallel computation are not well supported by popular systems languages.
- The emergence of multicore computers has generated worry and confusion.

2 SPECIFICATIONS
2.1 Notation

The syntax is specified using Extended Backus-Naur Form (EBNF):
Production = production_name "=" Expression "." .
Expression = Alternative { "|" Alternative } .
Alternative = Term { Term } .
Term = production_name | token [ "..." token ] | Group | Option | Repetition .
Group = "(" Expression ")" .
Option = "[" Expression "]" .
Repetition = "{" Expression "}" .
Productions are expressions constructed from terms and the following operators, in increasing precedence:
| alternation
() grouping
[] option (0 or 1 times)
{} repetition (0 to n times)
Lower-case production names are used to identify lexical tokens. Non-terminals are in CamelCase. Lexical symbols are enclosed in double quotes "" or back quotes ``.
The form a ... b represents the set of characters from a through b as alternatives.
2.2 Source code representation
Source code is Unicode text encoded in UTF-8. The text is not canonicalized, so a single accented code point is distinct from the same character constructed from combining an accent and a letter; those are treated as two code points. For simplicity, this document will use the term character to refer to a Unicode code point.
Each code point is distinct; for instance, upper and lower case letters are different characters.
Implementation restriction: For compatibility with other tools, a compiler may disallow the NUL character (U+0000) in the source text.
Characters
The following terms are used to denote specific Unicode character classes:
unicode_char = /* an arbitrary Unicode code point */ .
unicode_letter = /* a Unicode code point classified as "Letter" */ .
unicode_digit = /* a Unicode code point classified as "Digit" */ .
In The Unicode Standard 5.2, Section 4.5 General Category-Normative defines a set of character categories. Go treats those characters in category Lu, Ll, Lt, Lm, or Lo as Unicode letters, and those in category Nd as Unicode digits.
Letters and digits
The underscore character _ (U+005F) is considered a letter.
letter = unicode_letter | "_" .
decimal_digit = "0" ... "9" .
octal_digit = "0" ... "7" .
hex_digit = "0" ... "9" | "A" ... "F" | "a" ... "f" .
2.3 Lexical elements
Comments
There are two forms of comments:
1. Line comments start with the character sequence // and continue through the next newline. A line comment acts like a newline.
2. General comments start with the character sequence /* and continue through the character sequence */. A general comment that spans multiple lines acts like a newline, otherwise it acts like a space.
Comments do not nest.
Tokens
Tokens form the vocabulary of the Go language. There are four classes: identifiers, keywords, operators and delimiters, and literals. White space, formed from spaces (U+0020), horizontal tabs (U+0009), carriage returns (U+000D), and newlines (U+000A), is ignored except as it separates tokens that would otherwise combine into a single token. Also, a newline may trigger the insertion of a semicolon. While breaking the input into tokens, the next token is the longest sequence of characters that form a valid token.
Semicolons
The formal grammar uses semicolons ";" as terminators in a number of productions. Go programs may omit most of these semicolons using the following two rules:
1. When the input is broken into tokens, a semicolon is automatically inserted into the token stream at the end of a non-blank line if the line's final token is
o an identifier
o an integer, floating-point, character, or string literal
o one of the keywords break, continue, fallthrough, or return
o one of the operators and delimiters ++, --, ), ], or }
2. To allow complex statements to occupy a single line, a semicolon may be omitted before a closing ")" or "}".
To reflect idiomatic use, code examples in this document elide semicolons using these rules.
Identifiers
Identifiers name program entities such as variables and types. An identifier is a sequence of one or more letters and digits. The first character in an identifier must be a letter.
identifier = letter { letter | unicode_digit } .
a
_x9
ThisVariableIsExported
αβ
Some identifiers are predeclared.
Keywords
The following keywords are reserved and may not be used as identifiers.
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
Operators and Delimiters
The following character sequences represent operators, delimiters, and other special tokens:
+ & += &= && == != ( )
- | -= |= || < <= [ ]
* ^ *= ^= <- > >= { }
/ << /= <<= ++ = := , ;
% >> %= >>= -- ! ... . :
&^ &^=
Integer literals
An integer literal is a sequence of digits representing an integer constant. An optional prefix sets a non-decimal base: 0 for octal, 0x or 0X for hexadecimal. In hexadecimal literals, letters a-f and A-F represent values 10 through 15.
int_lit = decimal_lit | octal_lit | hex_lit .
decimal_lit = ( "1" ... "9" ) { decimal_digit } .
octal_lit = "0" { octal_digit } .
hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } .
42
0600
0xBadFace
170141183460469231731687303715884105727
Floating-point literals
A floating-point literal is a decimal representation of a floating-point constant. It has an integer part, a decimal point, a fractional part, and an exponent part. The integer and fractional part comprise decimal digits; the exponent part is an e or E followed by an optionally signed decimal exponent. One of the integer part or the fractional part may be elided; one of the decimal point or the exponent may be elided.
float_lit = decimals "." [ decimals ] [ exponent ] |
decimals exponent |
"." decimals [ exponent ] .
decimals = decimal_digit { decimal_digit } .
exponent = ( "e" | "E" ) [ "+" | "-" ] decimals .
0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5

2.4 Types

A type determines the set of values and operations specific to values of that type. A type may be specified by a (possibly qualified) type name (§Qualified identifier, §Type declarations) or a type literal, which composes a new type from previously declared types.
Type = TypeName | TypeLit | "(" Type ")" .
TypeName = QualifiedIdent.
TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
SliceType | MapType | ChannelType .
Named instances of the boolean, numeric, and string types are predeclared. Composite types”array, struct, pointer, function, interface, slice, map, and channel types”may be constructed using type literals.
A type may have a method set associated with it (§Interface types, §Method declarations). The method set of an interface type is its interface. The method set of any other named type T consists of all methods with receiver type T. The method set of the corresponding pointer type *T is the set of all methods with receiver *T or T (that is, it also contains the method set of T). Any other type has an empty method set. In a method set, each method must have a unique name.
The static type (or just type) of a variable is the type defined by its declaration. Variables of interface type also have a distinct dynamic type, which is the actual type of the value stored in the variable at run-time. The dynamic type may vary during execution but is always assignment compatible to the static type of the interface variable. For non-interface types, the dynamic type is always the static type.
Boolean types
A boolean type represents the set of Boolean truth values denoted by the predeclared constants true and false. The predeclared boolean type is bool.
Numeric types
A numeric type represents sets of integer or floating-point values. The predeclared architecture-independent numeric types are:
uint8 the set of all unsigned 8-bit integers (0 to 255)
uint16 the set of all unsigned 16-bit integers (0 to 65535)
uint32 the set of all unsigned 32-bit integers (0 to 4294967295)
uint64 the set of all unsigned 64-bit integers (0 to 18446744073709551615)
int8 the set of all signed 8-bit integers (-128 to 127)
int16 the set of all signed 16-bit integers (-32768 to 32767)
int32 the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
float32 the set of all IEEE-754 32-bit floating-point numbers
float64 the set of all IEEE-754 64-bit floating-point numbers
complex64 the set of all complex numbers with float32 real and imaginary parts
complex128 the set of all complex numbers with float64 real and imaginary parts
byte familiar alias for uint8
The value of an n-bit integer is n bits wide and represented using two's complement arithmetic.
There is also a set of predeclared numeric types with implementation-specific sizes:
uint either 32 or 64 bits
int either 32 or 64 bits
float either 32 or 64 bits
complex real and imaginary parts have type float
uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value
To avoid portability issues all numeric types are distinct except byte, which is an alias for uint8. Conversions are required when incompatible numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a particular architecture.
String types
A string type represents the set of string values. Strings behave like arrays of bytes but are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is string.
The elements of strings have type byte and may be accessed using the usual indexing operations. It is illegal to take the address of such an element; if s[i] is the ith byte of a string, &s[i] is invalid. The length of string s can be discovered using the built-in function len. The length is a compile-time constant if s is a string literal.
Array types
An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length and is never negative.
ArrayType = "[" ArrayLength "]" ElementType .
ArrayLength = Expression .
ElementType = Type .
The length is part of the array's type and must be a constant expression that evaluates to a non-negative integer value. The length of array a can be discovered using the built-in function len(a), which is a compile-time constant. The elements can be indexed by integer indices 0 through the len(a)-1 (§Indexes). Array types are always one-dimensional but may be composed to form multi-dimensional types.
[32]byte
[2*N] struct { x, y int32 }
[1000]*float64
[3][5]int
[2][2][2]float64 // same as [2]([2]([2]float64))
Slice types
A slice is a reference to a contiguous segment of an array and contains a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. A slice value may be nil.
SliceType = "[" "]" ElementType .
Like arrays, slices are indexable and have a length. The length of a slice s can be discovered by the built-in function len(s); unlike with arrays it may change during execution. The elements can be addressed by integer indices 0 through len(s)-1 (§Indexes). The slice index of a given element may be less than the index of the same element in the underlying array.
A slice, once initialized, is always associated with an underlying array that holds its elements. A slice therefore shares storage with its array and with other slices of the same array; by contrast, distinct arrays always represent distinct storage.
The array underlying a slice may extend past the end of the slice. The capacity is a measure of that extent: it is the sum of the length of the slice and the length of the array beyond the slice; a slice of length up to that capacity can be created by `slicing' a new one from the original slice (§Slices). The capacity of a slice a can be discovered using the built-in function cap(a) and the relationship between len() and cap() is:
0 <= len(a) <= cap(a)
The value of an uninitialized slice is nil. The length and capacity of a nil slice are 0. A new, initialized slice value for a given element type T is made using the built-in function make, which takes a slice type and parameters specifying the length and optionally the capacity:
make([]T, length)
make([]T, length, capacity)
The make() call allocates a new, hidden array to which the returned slice value refers. That is, executing
make([]T, length, capacity)
produces the same slice as allocating an array and slicing it, so these two examples result in the same slice:
make([]int, 50, 100)
new([100]int)[0:50]
Like arrays, slices are always one-dimensional but may be composed to construct higher-dimensional objects. With arrays of arrays, the inner arrays are, by construction, always the same length; however with slices of slices (or arrays of slices), the lengths may vary dynamically. Moreover, the inner slices must be allocated individually (with make).
Struct types
A struct is a sequence of named elements, called fields, each of which has a name and a type. Field names may be specified explicitly (IdentifierList) or implicitly (AnonymousField). Within a struct, non-blank field names must be unique.
StructType = "struct" "{" { FieldDecl ";" } "}" .
FieldDecl = (IdentifierList Type | AnonymousField) [ Tag ] .
AnonymousField = [ "*" ] TypeName .
Tag = string_lit .
// An empty struct.
struct {}
// A struct with 6 fields.
struct {
x, y int
u float
_ float // padding
A *[]int
F func()
}
A field declared with a type but no explicit field name is an anonymous field. Such a field type must be specified as a type name T or as a pointer to a type name *T, and T itself may not be a pointer type. The unqualified type name acts as the field name.
// A struct with four anonymous fields of type T1, *T2, P.T3 and *P.T4
struct {
T1 // field name is T1
*T2 // field name is T2
P.T3 // field name is T3
*P.T4 // field name is T4
x, y int // field names are x and y
}
The following declaration is illegal because field names must be unique in a struct type:
struct {
T // conflicts with anonymous field *T and *P.T
*T // conflicts with anonymous field T and *P.T
*P.T // conflicts with anonymous field T and *T
}
Fields and methods (§Method declarations) of an anonymous field are promoted to be ordinary fields and methods of the struct (§Selectors). The following rules apply for a struct type named S and a type named T:
¢ If S contains an anonymous field T, the method set of S includes the method set of T.
¢ If S contains an anonymous field *T, the method set of S includes the method set of *T (which itself includes the method set of T).
¢ If S contains an anonymous field T or *T, the method set of *S includes the method set of *T (which itself includes the method set of T).
A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. The tags are made visible through a reflection interface but are otherwise ignored.
// A struct corresponding to the TimeStamp protocol buffer.
// The tag strings define the protocol buffer field numbers.
struct {
microsec uint64 "field 1"
serverIP6 uint64 "field 2"
process string "field 3"
}
Pointer types
A pointer type denotes the set of all pointers to variables of a given type, called the base type of the pointer. A pointer value may be nil.
PointerType = "*" BaseType .
BaseType = Type .
*int
*map[string] *chan int
Function types
A function type denotes the set of all functions with the same parameter and result types. A function value may be nil.
FunctionType = "func" Signature .
Signature = Parameters [ Result ] .
Result = Parameters | Type .
Parameters = "(" [ ParameterList [ "," ] ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } .
ParameterDecl = [ IdentifierList ] ( Type | "..." [ Type ] ) .
Within a list of parameters or results, the names (IdentifierList) must either all be present or all be absent. If present, each name stands for one item (parameter or result) of the specified type; if absent, each type stands for one item of that type. Parameter and result lists are always parenthesized except that if there is exactly one unnamed result it may written as an unparenthesized type.
For the last parameter only, instead of a type one may write ... or ... T to indicate that the function may be invoked with zero or more additional arguments. If the type T is present in the parameter declaration, the additional arguments must all be assignment compatible with type T; otherwise they may be of any type.
func()
func(x int)
func() int
func(string, float, ...)
func(prefix string, values ... int)
func(a, b int, z float) bool
func(a, b int, z float) (bool)
func(a, b int, z float, opt ...) (success bool)
func(int, int, float) (float, *[]int)
func(n int) func(p *T)

3 TUTORIAL

3.1 Hello World
package main
import fmt "fmt" // Package implementing formatted I/O.
func main()
{
fmt.Printf("Hello, world")
}
Every Go source file declares, using a package statement, which package it's part of. It may also import other packages to use their facilities. This program imports the package fmt to gain access to our old, now capitalized and package-qualified, friend, fmt.Printf.
Functions are introduced with the func keyword. The main package's main function is where the program starts running (after any initialization).
String constants can contain Unicode characters, encoded in UTF-8. (In fact, Go source files are defined to be encoded in UTF-8.)
The comment convention is the same as in C++:
/* ... */
// ...

3.2 Semicolons

You might have noticed that our program has no semicolons. In Go code, the only place you typically see semicolons is separating the clauses of for loops and the like; they are not necessary after every statement.
In fact, what happens is that the formal language uses semicolons, much as in C or Java, but they are inserted automatically at the end of every line that looks like the end of a statement. You don't need to type them yourself.
For details about how this is done you can see the language specification, but in practice all you need to know is that you never need to put a semicolon at the end of a line. (You can put them in if you want to write multiple statements per line.) As an extra help, you can also leave out a semicolon immediately before a closing brace.
This approach makes for clean-looking, semicolon-free code. 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; 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.

3.3 Compiling

Go is a compiled language. At the moment there are two compilers. Gccgo is a Go compiler that uses the GCC back end. There is also a suite of compilers with different (and odd) names for each architecture: 6g for the 64-bit x86, 8g for the 32-bit x86, and more. These compilers run significantly faster but generate less efficient code than gccgo. At the time of writing (late 2009), they also have a more robust run-time system although gccgo is catching up.
Here's how to compile and run our program. With 6g, say,
$ 6g helloworld.go # compile; object goes into helloworld.6
$ 6l helloworld.6 # link; output goes into 6.out
$ 6.out
Hello, world; or Καλημέρα κόσμε; or こんにちは 世界
$
With gccgo it looks a little more traditional.
$ gccgo helloworld.go
$ a.out
Hello, world; or Καλημέρα κόσμε; or こんにちは 世界
$

3.4 Sorting

Interfaces provide a simple form of polymorphism. They completely separate the definition of what an object does from how it does it, allowing distinct implementations to be represented at different times by the same interface variable.
As an example, consider this simple sort algorithm taken from progs/sort.go:
13 func Sort(data Interface) {
14 for i := 1; i < data.Len(); i++ {
15 for j := i; j > 0 && data.Less(j, j-1); j-- {
16 data.Swap(j, j-1)
17 }
18 }
19 }
The code needs only three methods, which we wrap into sort's Interface:
07 type Interface interface {
08 Len() int
09 Less(i, j int) bool
10 Swap(i, j int)
11 }
We can apply Sort to any type that implements Len, Less, and Swap. The sort package includes the necessary methods to allow sorting of arrays of integers, strings, etc.; here's the code for arrays of int
33 type IntArray []int
35 func (p IntArray) Len() int { return len(p) } 36 func (p IntArray) Less(i, j int) bool { return p[i] < p[j] } 37 func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
Here we see methods defined for non-struct types. You can define methods for any type you define and name in your package.
And now a routine to test it out, from progs/sortmain.go. This uses a function in the sort package, omitted here for brevity, to test that the result is sorted.
12 func ints() {
13 data := []int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586}
14 a := sort.IntArray(data)
15 sort.Sort(a)
16 if !sort.IsSorted(a) {
17 panic()
18 }
19 }
If we have a new type we want to be able to sort, all we need to do is to implement the three methods for that type, like this:
30 type day struct {
31 num int
32 shortName string
33 longName string
34 }
36 type dayArray struct { 37 data []*day 38 }
40 func (p *dayArray) Len() int { return len(p.data) } 41 func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num } 42 func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i] }
3.5 Printing
The examples of formatted printing so far have been modest. In this section we'll talk about how formatted I/O can be done well in Go.
We've seen simple uses of the package fmt, which implements Printf, Fprintf, and so on. Within the fmt package, Printf is declared with this signature:
Printf(format string, v ...) (n int, errno os.Error)
That ... represents the variadic argument list that in C would be handled using the stdarg.h macros but in Go is passed using an empty interface variable (interface {}) and then unpacked using the reflection library. It's off topic here but the use of reflection helps explain some of the nice properties of Go's Printf, due to the ability of Printf to discover the type of its arguments dynamically.
For example, in C each format must correspond to the type of its argument. It's easier in many cases in Go. Instead of %llud you can just say %d; Printf knows the size and signedness of the integer and can do the right thing for you. The snippet
10 var u64 uint64 = 1<<64-1
11 fmt.Printf("%d %d\n", u64, int64(u64))
prints
18446744073709551615 -1
In fact, if you're lazy the format %v will print, in a simple appropriate style, any value, even an array or structure. The output of
14 type T struct {
15 a int
16 b string
17 }
18 t := T{77, "Sunset Strip"}
19 a := []int{1, 2, 3, 4}
20 fmt.Printf("%v %v %v\n", u64, t, a)
is
18446744073709551615 {77 Sunset Strip} [1 2 3 4]
You can drop the formatting altogether if you use Print or Println instead of Printf. Those routines do fully automatic formatting. The Print function just prints its elements out using the equivalent of %v while Println inserts spaces between arguments and adds a newline. The output of each of these two lines is identical to that of the Printf call above.
21 fmt.Print(u64, " ", t, " ", a, "\n")
22 fmt.Println(u64, t, a)
If you have your own type you'd like Printf or Print to format, just give it a String() method that returns a string. The print routines will examine the value to inquire whether it implements the method and if so, use it rather than some other formatting. Here's a simple example.
09 type testType struct {
10 a int
11 b string
12 }
14 func (t *testType) String() string { 15 return fmt.Sprint(t.a) + " " + t.b 16 }
18 func main() { 19 t := &testType{77, "Sunset Strip"} 20 fmt.Println(t) 21 }
Since *testType has a String() method, the default formatter for that type will use it and produce the output
77 Sunset Strip
Observe that the String() method calls Sprint (the obvious Go variant that returns a string) to do its formatting; special formatters can use the fmt library recursively.
Another feature of Printf is that the format %T will print a string representation of the type of a value, which can be handy when debugging polymorphic code.
It's possible to write full custom print formats with flags and precisions and such, but that's getting a little off the main thread so we'll leave it as an exploration exercise.
You might ask, though, how Printf can tell whether a type implements the String() method. Actually what it does is ask if the value can be converted to an interface variable that implements the method. Schematically, given a value v, it does this:
type Stringer interface {
String() string
}
s, ok := v.(Stringer); // Test whether v implements "String()"
if ok {
result = s.String()
} else {
result = defaultOutput(v)
}
The code uses a ``type assertion'' (v.(Stringer)) to test if the value stored in v satisfies the Stringer interface; if it does, s will become an interface variable implementing the method and ok will be true. We then use the interface variable to call the method. (The ''comma, ok'' pattern is a Go idiom used to test the success of operations such as type conversion, map update, communications, and so on, although this is the only appearance in this tutorial.) If the value does not satisfy the interface, ok will be false.
In this snippet the name Stringer follows the convention that we add ''[e]r'' to interfaces describing simple method sets like this.
One last wrinkle. To complete the suite, besides Printf etc. and Sprintf etc., there are also Fprintf etc. Unlike in C, Fprintf's first argument is not a file. Instead, it is a variable of type io.Writer, which is an interface type defined in the io library:
type Writer interface {
Write(p []byte) (n int, err os.Error);
}
(This interface is another conventional name, this time for Write; there are also io.Reader, io.ReadWriter, and so on.) Thus you can call Fprintf on any type that implements a standard Write() method, not just files but also network channels, buffers, whatever you want.
3.6 Prime numbers
Now we come to processes and communication”concurrent programming. It's a big subject so to be brief we assume some familiarity with the topic.
A classic program in the style is a prime sieve. (The sieve of Eratosthenes is computationally more efficient than the algorithm presented here, but we are more interested in concurrency than algorithmics at the moment.) It works by taking a stream of all the natural numbers and introducing a sequence of filters, one for each prime, to winnow the multiples of that prime. At each step we have a sequence of filters of the primes so far, and the next number to pop out is the next prime, which triggers the creation of the next filter in the chain.
Here's a flow diagram; each box represents a filter element whose creation is triggered by the first number that flowed from the elements before it.
To create a stream of integers, we use a Go channel, which, borrowing from CSP's descendants, represents a communications channel that can connect two concurrent computations. In Go, channel variables are references to a run-time object that coordinates the communication; as with maps and slices, use make to create a new channel.
Here is the first function in progs/sieve.go:
09 // Send the sequence 2, 3, 4, ... to channel 'ch'.
10 func generate(ch chan int) {
11 for i := 2; ; i++ {
12 ch <- i // Send 'i' to channel 'ch'.
13 }
14 }
The generate function sends the sequence 2, 3, 4, 5, ... to its argument channel, ch, using the binary communications operator <-. Channel operations block, so if there's no recipient for the value on ch, the send operation will wait until one becomes available.
The filter function has three arguments: an input channel, an output channel, and a prime number. It copies values from the input to the output, discarding anything divisible by the prime. The unary communications operator <- (receive) retrieves the next value on the channel.
16 // Copy the values from channel 'in' to channel 'out',
17 // removing those divisible by 'prime'.
18 func filter(in, out chan int, prime int) {
19 for {
20 i := <-in // Receive value of new variable 'i' from 'in'.
21 if i % prime != 0 {
22 out <- i // Send 'i' to channel 'out'.
23 }
24 }
25 }
The generator and filters execute concurrently. Go has its own model of process/threads/light-weight processes/coroutines, so to avoid notational confusion we call concurrently executing computations in Go goroutines. To start a goroutine, invoke the function, prefixing the call with the keyword go; this starts the function running in parallel with the current computation but in the same address space:
go sum(hugeArray); // calculate sum in the background
If you want to know when the calculation is done, pass a channel on which it can report back:
ch := make(chan int);
go sum(hugeArray, ch);
// ... do something else for a while
result := <-ch; // wait for, and retrieve, result
Back to our prime sieve. Here's how the sieve pipeline is stitched together:
28 func main() {
29 ch := make(chan int) // Create a new channel.
30 go generate(ch) // Start generate() as a goroutine.
31 for {
32 prime := <-ch
33 fmt.Println(prime)
34 ch1 := make(chan int)
35 go filter(ch, ch1, prime)
36 ch = ch1
37 }
38 }
Line 29 creates the initial channel to pass to generate, which it then starts up. As each prime pops out of the channel, a new filter is added to the pipeline and its output becomes the new value of ch.
The sieve program can be tweaked to use a pattern common in this style of programming. Here is a variant version of generate, from progs/sieve1.go:
10 func generate() chan int {
11 ch := make(chan int)
12 go func(){
13 for i := 2; ; i++ {
14 ch <- i
15 }
16 }()
17 return ch
18 }
This version does all the setup internally. It creates the output channel, launches a goroutine running a function literal, and returns the channel to the caller. It is a factory for concurrent execution, starting the goroutine and returning its connection.
The function literal notation (lines 12-16) allows us to construct an anonymous function and invoke it on the spot. Notice that the local variable ch is available to the function literal and lives on even after generate returns.
The same change can be made to filter:
21 func filter(in chan int, prime int) chan int {
22 out := make(chan int)
23 go func() {
24 for {
25 if i := <-in; i % prime != 0 {
26 out <- i
27 }
28 }
29 }()
30 return out
31 }
The sieve function's main loop becomes simpler and clearer as a result, and while we're at it let's turn it into a factory too:
33 func sieve() chan int {
34 out := make(chan int)
35 go func() {
36 ch := generate()
37 for {
38 prime := <-ch
39 out <- prime
40 ch = filter(ch, prime)
41 }
42 }()
43 return out
44 }
Now main's interface to the prime sieve is a channel of primes:
46 func main() {
47 primes := sieve()
48 for {
49 fmt.Println(<-primes)
50 }
51 }
3.7 Multiplexing
With channels, it's possible to serve multiple independent client goroutines without writing an explicit multiplexer. The trick is to send the server a channel in the message, which it will then use to reply to the original sender. A realistic client-server program is a lot of code, so here is a very simple substitute to illustrate the idea. It starts by defining a request type, which embeds a channel that will be used for the reply.
09 type request struct {
10 a, b int
11 replyc chan int
12 }
The server will be trivial: it will do simple binary operations on integers. Here's the code that invokes the operation and responds to the request:
14 type binOp func(a, b int) int
16 func run(op binOp, req *request) { 17 reply := op(req.a, req.b) 18 req.replyc <- reply 19 }
Line 14 defines the name binOp to be a function taking two integers and returning a third.
The server routine loops forever, receiving requests and, to avoid blocking due to a long-running operation, starting a goroutine to do the actual work.
21 func server(op binOp, service chan *request) {
22 for {
23 req := <-service
24 go run(op, req) // don't wait for it
25 }
26 }
We construct a server in a familiar way, starting it and returning a channel connected to it:
28 func startServer(op binOp) chan *request {
29 req := make(chan *request)
30 go server(op, req)
31 return req
32 }
Here's a simple test. It starts a server with an addition operator and sends out N requests without waiting for the replies. Only after all the requests are sent does it check the results.
34 func main() {
35 adder := startServer(func(a, b int) int { return a + b })
36 const N = 100
37 var reqs [N]request
38 for i := 0; i < N; i++ {
39 req := &reqs[i]
40 req.a = i
41 req.b = i + N
42 req.replyc = make(chan int)
43 adder <- req
44 }
45 for i := N-1; i >= 0; i-- { // doesn't matter what order
46 if <-reqs[i].replyc != N + 2*i {
47 fmt.Println("fail at", i)
48 }
49 }
50 fmt.Println("done")
51 }
One annoyance with this program is that it doesn't shut down the server cleanly; when main returns there are a number of lingering goroutines blocked on communication. To solve this, we can provide a second, quit channel to the server:
32 func startServer(op binOp) (service chan *request, quit chan bool) {
33 service = make(chan *request)
34 quit = make(chan bool)
35 go server(op, service, quit)
36 return service, quit
37 }
It passes the quit channel to the server function, which uses it like this:
21 func server(op binOp, service chan *request, quit chan bool) {
22 for {
23 select {
24 case req := <-service:
25 go run(op, req) // don't wait for it
26 case <-quit:
27 return
28 }
29 }
30 }
Inside server, the select statement chooses which of the multiple communications listed by its cases can proceed. If all are blocked, it waits until one can proceed; if multiple can proceed, it chooses one at random. In this instance, the select allows the server to honor requests until it receives a quit message, at which point it returns, terminating its execution.
All that's left is to strobe the quit channel at the end of main:
40 adder, quit := startServer(func(a, b int) int { return a + b })
...
55 quit <- true
There's a lot more to Go programming and concurrent programming in general but this quick tour should give you some of the basics.

4 INSTALLATION

GO language promoted by Google is a new system programming language said to be expressive, concurrent, garbage-collected. The language is still very young and there is no ready made package available for ubuntu. You can install it and try out the features from the version control repository of go .
Let us see how you can do this. I did it on ubuntu 9.04.

4.1 Install Pre-requisites on ubuntu.

You need gcc and some supporting software like bison to compile go. Install the following.
$ sudo apt-get install bison gcc libc6-dev ed.
The go repository uses mercurial version controls system .
Install mercurial with the following command.
$ apt-get install mercurial
4.2 Set up the environment variables.
I am assuming that you are planning to install go under a folder
named go in your home directory.
In my case it is /home/fermi/go
Create it with
$mkdir go
Now create another direcory inside go .
$ mkdir go/bin
The above directory will contain your go compiler.
Next, you have to set u several variables.
$ export GOROOT=/home/fermi/go/hg
$ export GOOS=linux
$ export GOARCH=386
$ export GOBIN=/home/fermi/go/bin
( Note: You need not create the folder hg. You can also add the above
four lines along with the PATH variable below to the .bashrc file
if you are planning to use go regularly.)
Update your PATH variable .
$ export PATH=$PATH:$GOBIN
Check the environment variables with.
$ env | grep '^GO'
I got like this.
GOBIN=/home/fermi/go/bin/
GOARCH=386
GOROOT=/home/fermi/go/hg
GOOS=linux
4.3 Grab the source code from mercurial
$hg clone -r release https://go.googlecodehg/ $GOROOT
It created /home/fermi/go/hg and downloaded several files to it.
To build the Go distribution run.
4.4 Compile Go
$ cd $GOROOT/src
$ ./all.bash
Now wait for some time. The compilations will proceed and will be
completed with the following message
--- cd ../test
N known bugs; 0 unexpected bugs
4.5 Test go
Your go language system is ready to go.Big Grin
Now let us write a hello world program and test it.
Create the following program in your favourite editor and save it as hello.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
To compile hello.go run.
$ 8g hello.go
The above command produced and intermediate file hello.8.
Next you have to link it.
$ 8l hello.8
The executable is placed as 8.out. Finally run the executable.
$./8.out

5 ABOUT GO LANGUAGE

Google's new programming language, called Go, took the application development world by storm when the search giant released it Nov. 10. The ambitious technology's pedigree features programming experts from the Unix world, including Ken Thompson, who teamed with Dennis Ritchie to create Unix. Created as a systems programming language to help speed up development of systems inside Google, Go is now viewed as a general-purpose language for Web development, mobile development, addressing parallelism and a lot more.

5.1 Where did the idea for Go come from?

Pike, Thompson and Robert Griesemer of Java HotSpot virtual machine and V8 JavaScript engine fame, decided to make a go of developing a new language out of frustration with the pace of building software. Said Pike:
"In Google we have very large software systems and we spent so long literally waiting for compilations, even though we have distributed compilation and parallelism in all of these tools to help, it can take a very long time to build a program. Even incremental builds can be slow. And we looked at this and realized many of the reasons for that are just fundamental in working in languages like C and C++, and we needed a different approach. We also decided the tools that everybody used were also slow. So we wanted to start from scratch to write the kind of programs we need to write here at Google in a way that the tools could be really efficient and the build cycles could be very short."

5.2 Go is a multipurpose language

Pike said Go is appropriate for a broad spectrum of uses, including Web programming, mobile programming and systems programming. "We based it on our ideas of what we think systems programming should be like," he said.
Then a Google engineer told the team he wanted to do a port to ARM processors for the Go language because he wanted to do some work in robotics. With the ARM support, "We can now run Go code in Android phones, which is a pretty exciting possibility," Pike said. "Of course, ARMs also run inside a lot of the other phones out there, so maybe it's a mobile language."
He added, "I think people, once they absorb it a little bit more, will see the advantage of having a modern language in some ways that actually runs really fast. And it's an interesting candidate to think of as an alternative for JavaScript in the browser.
"Although getting Go supported inside browsers is going to be a seriously challenging undertaking ... but it is an interesting thing to think about because it has a lot of the advantages of JavaScript as a lightweight, fun language to play with. But it's enormously more efficient. So some of the big, heavy, client-oriented applications out there like Google Wave would be much zippier if they were written in Go, but of course they can't be written in Go because it doesn't run in a browser yet. But I'd like to see some stuff in that direction, too, although how that's going to happen I don't know."

5.3 Will Go be the next big thing in programming?

Asked whether he thought Go might be the next big thing, Pike replied, "I'd be thrilled if that happened, but I don't expect it."
He added that he hopes the language will grow on its own merits. Then Pike noted a significant difference between Go and Java.
"It's not a Google official language the way that, say, Java was a Sun [Microsystems] official language," Pike said. "We're really launching this as an open-source experimental toy for people to play with. It needs time ... to become something that people would want to build companies around or anything like that. It may never get there. But, so far, the response has been really positive."

5.4 Google's Go owes some debt to Bell Labs' Plan 9

Plan 9 is a distributed operating system developed as the research successor to Unix at Bell Labs. Pike and Thompson were part of the original Plan 9 team at Bell Labs. And Go team member Russ Cox also was a Plan 9 developer.
Although there was not a lot of direct use of Plan 9 technology in creating Go, the link between team members is not the only connection.
The Plan 9 team produced some programming languages of its own, such as Alef and Limbo, which had a slight impact on the direction of Go. "We didn't pull out those languages and look at them again," Pike said. "But I think a better way to express it is that, particularly on the concurrency side of things”the parallel programming side of things”those languages are kind of in the same family tree and inspired by the same approach."
Pike added, "Ken's compiler is entirely new ... it uses the Plan 9 compiler suite, linker and assembler, but the Go compiler is all new. So we borrowed a little technology, but that's just the compiler, that's not the vision. And naturally some of the people working on the project and implimentation were around from the Plan 9 days, so there's got to be some intellectual cross-breeding there. But this wasn't an attempt to do a Plan 9. This is a language, not an operating system, and they address different things. Go doesn't even have a Plan 9 port at this point, although it would be nice to have one."

5.5 Seven engineers join Google's Go team

Pike and Griesemer were officemates who groused about the problems with programming. Once they decided to try to create a language they invited Thompson to join, because "Ken really understands how to make things go fast and has really good ideas about things ... and besides he was in the next office. And in about 5 minutes we decided the three of us could really make something happen."
Meanwhile, another Google engineer, Ian Taylor, saw the draft specification for the language and told the trio he had written a GCC front end for it. So he joined the team. Russ Cox joined about a year ago. And in the last couple of months another Google engineer named Adam Langley joined the team and has been helping out with a lot of library work and getting an SSL (Secure Sockets Layer) implementation in native Go, Pike said. Jini Kim is the product manager for Go and organized many aspects of the launch.

5.6 How Go speeds up development

"One of the big problems with development that sounds very uninteresting and unsexy [is] maintaining the dependencies”what you need to build first in order to build this thing you're trying to build now, such as the libraries, the packages, layers of software," Pike said. "And languages like C++ and C in particular make it very hard to guarantee that you're not building anything that you don't need to. And we've investigated this in some detail and found that it's a huge reason, almost the dominant reason why build times are so slow for large C++ applications.
"So one of the things we did with Go is we are very rigid about dependency specification. And the language actually yells if you try to pull in a dependency you don't actually use. This guarantees a minimal tree and that really helps the build. And there's one more very technical thing that is really important and that's the idea that we pull the dependency information up the tree as we go so that you only look at anything once. You never compile anything more than once when you're doing a build. And that's a huge improvement in performance relative to the normal C family of languages."
On this point, Pike also said, "The languages people use for building large software systems nowadays are typically languages like C++ and Java, which were designed pretty much a generation ago in terms of programming abilities and understanding. And they're not aging very well. And we realize that there are things like the advent of multicore processing and the dominance of cluster computing and things like that really needed a rethink at the language level. So we tried to bring in some of our background in distributed systems and concurrent programming and stuff like that."

5.7 Google Go has an unusual type system

Pike said some have described Go as object-oriented programming without objects. Instead of having a notion of a class and then defining all the methods for that class and then subclassing and so on, Go is much more orthogonal, he said.
"You write down the types as storage buckets that implement things," Pike said. "And then you can have what we call interfaces, which are pure abstractions about behaviors of those things. And when you want to write a program that needs something like a 'write' or a 'sort' you just say I need something that knows how to write or that knows how to sort. You don't have to explicitly define a subclass of something from a sorting interface and build it down. It's all sort of much more compiler-derived instead of programmer-specified. And a smaller point, but it matters to some of us is that you can put a method, in the object-oriented sense, in any type in the system."
Moreover, in Go the type system is fully statically typed, Pike said. "In the sense that, let's say, going back to the sorting idea ... At compile time you know that everything coming in can implement the sorting interface or it would not statically compile," he said. "But there is dynamic type information under the covers that programs can use to do interesting things. So it's a statically typed language with a little bit of polymorphism mixed in. That's the best way to say it."

5.8 Google builds Go to support concurrency

Although most of the larger machines delivered today have multiple cores inside them, the common programming languages that are out there don't really have enough support for using those cores efficiently, Pike said.
Developers can find libraries to help with this, "but they're very difficult to use and the primitives are fairly clumsy," he added. "One of our goals in Go was to make a language that could use those processors well, particularly for the kind of server-side programming that we do here at Google where you have many client requests coming into a machine that's multiplexing them. And Go is a really good language for writing multiplex servers in, where you use these things called 'go' routines, which are kind of like threads but lighter-weight, and some communication primitives to do the multiplexing."
In fact, the Golang.org Website is written in Go and is doing exactly that, Pike said.
"It's a parallel Web server with multiple internal threads of control for each client request that comes in," he said. "And it works really well. It seems to be a good way to go. We haven't built it at the kind of scale we need yet to say this is definitely the way to go. And there's definitely some more library support needed for things like scheduling and so on. But from a starting point it's a really good place to be."

5.9 In terms of programming languages, Google Go is most like...

Rather than viewing Go as competing with other languages for developer attention, Pike said he thinks Go simply provides an alternative.
Moreover, he said he thinks programmers who are used to developing systems software and are used to languages like C and C++ and Java will find Go interesting because of the different take it has.
"And it's also sort of roughly in that general category of language," Pike added. "Especially in terms of performance. It's not as fast as C, but it's not much slower. But on the other hand, programmers who are used to more of the dynamic languages such as Python, Ruby and maybe JavaScript have remarked that they think Go is interesting because they think Go gives them the speed of a compiled language, but a lot of the nice, light dynamic feel of those [dynamic] languages."

5.10 To thrive, Google Go needs to sprout an ecosystem

Pike said he "hopes" that the language will generate an ecosystem. However, "This is a kind of skunkworks project and implimentation," he said. "We put out what we've got so far, but one of the big reasons we did that is we want people to help us expand it and put in support for the Windows operating system and also help us develop tools such as IDEs [integrated development environments] and things like that.
As an open-source project and implimentation I think it will develop an IDE and an ecosystem, as it seems to be really well received. But I really can't predict how big that ecosystem will get. We'd certainly love to see it thrive."

5.11 Google Go is open source to the bone

Pike said he believes that part of the advantage of Go being totally open source is the community can help generate an ecosystem. "If the community gets excited and starts building up the ecosystem it will grow and thrive on its own," he said. Regarding the Go language Website, Pike noted that it is not Google-branded. "It's a different Website," he said. "We're happy it's from Google and we're going to use it internally for a lot of our stuff, we hope. But it really is an open-source project and implimentation and we want the community to help us make something happen."
Also, in a nod to the openness of the Go language and the might of the Eclipse open-source development platform, Pike said, "I would love to see Eclipse support Go. We've talked about that for probably a year now, but we haven't gotten anyone to do the work. It's a fair bit of effort to make a proper plug-in for Eclipse."
In response, Ian Skerrett, director of marketing at the Eclipse Foundation, told eWEEK: "I think it would be great to see a Go plug-in for Eclipse. Eclipse has support for lots of languages, including some of the 'newer' ones like Scala, Groovy [and] Ruby, so adding Go would make sense. It will really depend on people in the Go community seeing the need and creating the plug-in."
5.12 Next steps for Google Go

Regarding what the Go team plans to do in the near term, Pike said:
"We've got a few language features that we've been batting around for awhile that we'd like to continue to bat around and see if we can make them fit”things like ... [for example,] union types is something that we think we have a good handle on that we haven't had time to implement. The run-time needs a fair bit of development. The garbage collector works just fine but it's not robust or efficient enough to be a practical solution for a large-scale server. We're very conscious of that. But there's some very clever work at IBM that's been published that we think we can use to guide a much better garbage collector. I think we can solve that problem well. And once we do we'll have achieved something really nice, which is a native compiled language with garbage collection that works well in a systems environment.
"Java suffered quite a bit from that and we're very aware of the issues that garbage collection and systems programming have. You tend to worry about pauses where the garbage collector is running. We have to make sure we don't introduce those. Those are the big things that we're thinking about. But we also need a lot of tools. We need a debugger, and then second-order things like IDEs and ports to Windows and other operating systems."


6 FEATURES/FACTS

a systems programming language
expressive, concurrent, garbage-collected
Go is ¦
¦ simple
package main
import "fmt"
func main() {
fmt.Printf("Hello\n")
}
¦ fast
Go compilers produce fast code fast. Typical builds take a fraction of a second yet the resulting programs run nearly as quickly as comparable C or C++ code.
¦ safe
Go is type safe and memory safe. Go has pointers but no pointer arithmetic. For random access, use slices, which know their limits.
¦ concurrent
Go promotes writing systems and servers as sets of lightweight communicating processes, called goroutines, with strong support from the language. Run thousands of goroutines if you want”and say good-bye to stack overflows.
¦ fun
Go has fast builds, clean syntax, garbage collection, methods for any type, and run-time reflection. It feels like a dynamic language but has the speed and safety of a static language. It's a joy to use.

7 REFERENCES

1. Brownlee, John (2009-11-13). "Google didnâ„¢t Google Go before naming their programming language". Geek.com. geekarticles/news/google-didnt-google-go-before-naming-their-programming-language-20091113/. Retrieved 2010-01-18.
2. Claburn, Thomas (2009-11-11). "Google 'Go' Name Brings Accusations Of 'Evil'". InformationWeek. informationweeknews/software/web_services/showArticle.jhtml?articleID=221601351. Retrieved 2009-11-14.
3. Clark, K.L.; McCabe, F.G. (2003). "Go! for multi-threaded deliberative agents". International Conference on Autonomous Agents (AAMAS'03): 964 - 965. doi:10.1145/860575.860747. portal.acmcitation.cfm?doid=860575.860747.
4. "Issue 9 - go - I have already used the name for *MY* programming language". code.google.com. 2009-11-10. code.googlep/go/issues/detail?id=9. Retrieved 2009-11-14.
5. Clark, K.L.; McCabe, F.G. (2006). "Ontology oriented programming in go!". Applied Intelligence 24(3):189-204.doi:10.1145/860575.860747. portal.acmcitation.cfm?id=1127540.
6. Clark, K.L.; McCabe, F.G. (2004). "Go!”A Multi-Paradigm Programming Language for Implementing Multi-Threaded Agents". Annals of Mathematics and Artificial Intelligence
41(2-4):171-206.doi:10.1023/B:AMAI.0000031195.87297.d9. portal.acmcitation.cfm?id=998367.
Use Search at http://topicideas.net/search.php wisely To Get Information About Project Topic and Seminar ideas with report/source code along pdf and ppt presenaion
Reply
sabithsabumon
Active In SP
**

Posts: 3
Joined: Jul 2010
#2
15-07-2010, 06:52 PM

i want goprogrmming language full report
Reply
project report helper
Active In SP
**

Posts: 2,270
Joined: Sep 2010
#3
22-10-2010, 11:54 AM



.doc   New Microsoft Office Word 97 - 2003 Document.doc (Size: 126.5 KB / Downloads: 62)

.doc   go programoing.doc (Size: 314 KB / Downloads: 85)
GO PROGRAMMING LANGUAGE

Introduction

This document is a tutorial introduction to the basics of the Go programming language, intended for programmers familiar with C or C++. It is not a comprehensive guide to the language; at the moment the document closest to that is the language specification. After you've read this tutorial, you might want to look at Effective Go, which digs deeper into how the language is used. Also, slides from a 3-day course about Go are available: Day 1, Day 2, Day 3.
The presentation here proceeds through a series of modest programs to illustrate key features of the language. All the programs work (at time of writing) and are checked into the repository in the directory /doc/progs/.
Program snippets are annotated with the line number in the original file; for cleanliness, blank lines remain blank.
Reply
seminar surveyer
Active In SP
**

Posts: 3,541
Joined: Sep 2010
#4
30-12-2010, 04:07 PM



ANIL KUMAR REDDY


.ppt   GO1.ppt (Size: 687 KB / Downloads: 92)

Go is a
New
Experimental
Concurrent
Garbage-Collected Language.

Features
The most important features of Go are
the feel of a dynamic language with the safety of a static type system.
compile to machine language so it runs fast.
real run-time that supports GC, concurrency.
lightweight, flexible type system.
has methods but not a
conventional object-oriented
language.
Compiled

Go is a compiled language. At the moment there are two compilers.
 Gccgo is a Go compiler that uses the GCC back end. There is also a suite of compilers with different (and odd) names for each architecture: 6g for the 64-bit x86, 8g for the 32-bit x86, and more.
These compilers run
significantly faster but
generate less efficient code
than gccgo.

Similarity
Go is having a similar language structure as of C.
Declarations are introduced by a keyword (var,
const, type, func) and look reversed compared to C. Examples are
var i int
const PI = 22/7
The “:=“short declaration
Within functions (only), declarations of the form var v = value can be shortened to v := value (Another reason for the name/type reversal.)
The type is that of the value (for ideal numbers, get int or float, accordingly.)
a, b, c, d := 1, 2.0, "three", FOUR
These are used a lot and are
available in places such as for
loop initializers.



Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page

Quick Reply
Message
Type your reply to this message here.


Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  web spoofing full report computer science technology 13 8,923 20-05-2016, 11:59 AM
Last Post: Dhanabhagya
  cyber crime in hindi language jaseelati 0 228 23-02-2015, 01:40 PM
Last Post: jaseelati
  advantages and disadvantages of computer in tamil language jaseelati 0 378 05-02-2015, 04:51 PM
Last Post: jaseelati
  google glass seminar report pdf jaseelati 0 326 21-01-2015, 01:41 PM
Last Post: jaseelati
  google glass ieee paper pdf jaseelati 0 403 01-01-2015, 04:25 PM
Last Post: jaseelati
  CGI PROGRAMMING LABORATORY seminar ideas 1 579 08-10-2014, 08:16 AM
Last Post: OtlBY
  android full report computer science technology 57 73,127 24-09-2014, 05:05 PM
Last Post: Michaelnof
  Object Oriented Programming with Java seminar paper 2 1,067 18-09-2014, 03:24 PM
Last Post: Radhika.m
  steganography full report project report tiger 23 25,734 01-09-2014, 11:05 AM
Last Post: computer science crazy
  3D PASSWORD FOR MORE SECURE AUTHENTICATION full report computer science topics 144 92,342 13-05-2014, 10:16 AM
Last Post: seminar project topic