Go Premier

Ibrahim AshShohail (@ibrasho)

The Go gopher was designed by Renee French (http://reneefrench.blogspot.com/)

The design is licensed under the Creative Commons 3.0 Attributions license.

Contents

The Go gopher was designed by Renee French (http://reneefrench.blogspot.com/)

The design is licensed under the Creative Commons 3.0 Attributions license.

  • What is Go?
    • History
    • Purpose
    • Characteristics
    • Runtime
  • Who is using Go?
  • Why is Go bad?
  • A Tour of Go
  • Resource

History

  • 2007: It all started in Google (Robert Griesemer, Rob Pike and Ken Thompson)
  • Early 2008: Ken started working on a compiler.
  • Mid 2008: Attempts at a production compiler.
  • Late 2008: Russ Cox joined and helped move the language and libraries from prototype to reality.
  • 2009: Go became a public open source project.
  • 2012: Go 1.0 was released.

The Purpose of Go

​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.

Our goal is definitely not to beat C++ on performance. The goal for Go is to be near C++ in terms of performance but at the same time be a much more productive environment and language, so that you’d rather program in Go.

Main Characteristics

  • Statically-typed, compiled language
  • Garbage collected.
  • interface-based object-orientation.
  • Simple concurrency primitives (goroutines & channels).
  • Performant.
  • Fast compilation.
  • Extensive runtime.

Go Runtime

Go does have an extensive library, called the runtime, that is part of every Go program. The runtime library implements garbage collection, concurrency, stack management, and other critical features of the Go language. Although it is more central to the language, Go's runtime is analogous to libc, the C library.

It is important to understand, however, that Go's runtime does not include a virtual machine, such as is provided by the Java runtime. Go programs are compiled ahead of time to native machine code. Thus, although the term is often used to describe the virtual environment in which a program runs, in Go the word “runtime” is just the name given to the library providing critical language services.

Go Users

Use cases

  • System programming
  • Network programming
  • Concurrent programing
  • Automation and Command-line tools

Is Go an object-oriented language?

  • Yes and no...
  • Go has types and methods and allows an object-oriented style of programming
  • But there is no type hierarchy.
  • “interface”s in Go provides a different approach that we believe is easy to use and in some ways more general.
  • There are also ways to embed types in other types to provide something analogous—but not identical—to subclassing.
  • Methods in Go are more general.
  • They can be defined for any sort of data, even built-in types.
  • The lack of a type hierarchy makes “objects” in Go feel much more lightweight.

Why Go is Bad?

  • The mascot, really!?
  • un-googlable name (it's better now...)
  • too simple
  • no OOP
  • no exceptions
  • no generics
  • no function/operator overloading
  • no immutables, pattern matching, ...
  • error handling
  • bad dependency management (we are solving this)
  • GOPATH...
  • ...

A Tour of Go

Testing

// ./add.go
package add

func Add(x, y int) int {
	sum := x

	for y > 0 {
		y++
	}

	return sum
}

Testing

// ./add_test.go
package add

func TestAdd(t *testing.T) int {
	cases := struct {
		x, y     int
		expected int
	}{
		{0, 0, 0},
		{1, 2, 3},
		{5, 5, 10},
		{5, -5, 0},
		{-5, 5, 0},
		{-5, -5, -10},
	}

	for _, c := range cases {
		if got := Add(c.x, c.y); got != c.expected {
			t.Errorf("Add(%s, %s) failed: expected: %s, got: %s",
				c.x, c.y, c.expected, got)
		}
	}
}

Testing

Go Toolchain

Go Toolchain

Resources

Learning Go

Community

Starters

Go Deeper

Books

Packages

شكرًا لكم

@ibrasho

Go

By Ibrahim AshShohail