Minggu, 09 Oktober 2016

Learning Golang (Part 1)

Overview
Go (often referred to as golang) is a Free and open source 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 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", is developed as open source software and targets various platforms including Linux, OS X, Windows, various BSD and Unix versions, and since 2015 also mobile devices, including smartphones. A second compiler, gccgo, is a GCC frontend. The "gc" toolchain is 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 new language was to:

  1. be statically typed, scalable to large systems (as Java and C++); 
  2. be productive and readable, without too many mandatory keywords and repetition ("light on the page" like dynamic languages); 
  3. not require tooling, but support it well
  4. support 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. Go 1.7 added "one tiny language change" and one port to macOS 10.12 Sierra plus some experimental ports, e.g. for Linux on z Systems (linux/s390x). Some library changes apply, and e.g. Unicode 9.0 is now supported.

Design Principles of Golang

  1. Support for environment adopting patterns similar to dynamic languages. For example type inference (x := 0 is valid declaration of a variable x of type int) 
  2. Compilation time is fast.
  3. InBuilt concurrency support: light-weight processes (via goroutines), channels, select statement.
  4. Conciseness, Simplicity, and Safety
  5. Support for Interfaces and Type embedding.
  6. Production of statically linked native binaries without external dependencies. 
Features excluded intentionally 

  1. To keep language simple and concise, following features commonly available in similar languages are ommitted
  2. No support for type inheritance
  3. No support for method or operator overloading
  4. No support for circular dependencies among packages
  5. No support for pointer arithmetic
  6. No support for assertions
  7. No support for generic programming 
Getting Started 
The source files for Go programs are named with the extension ".go". First of all we need a Golang installable archieve to start it. You can download it here

    Install on Linux, Mac OS X, and FreeBSD tarballs 
      Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example:
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
Choose the archive file appropriate for your installation. For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is called go1.2.1.linux-amd64.tar.gz. (Typically these commands must be run as root or through sudo.) Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:
export PATH=$PATH:/usr/local/go/bin

    Installation on Windows

    Use the MSI file and follow the prompts to install the Go tools. By default, the installer uses the Go distribution in c:\Go. The installer should set the c:\Go\bin directory in window's PATH environment variable. Restart any open command prompts for the change to take effect.

   Test it
    Create a go file, save it as hello.go in D:\>Go_Workspace.
Filename : hello.go
package main

import "fmt"

func main() {
   fmt.Println("Hello world!")
}
  Now run the test.go to see the result:
D:\Go_Workspace>go run hello.go
Verify the Output
Hello world!
That's it for now, next we will learn the basics of Golang


Source :
- https://en.wikipedia.org/wiki/Go_(programming_language) 
- https://www.tutorialspoint.com/go/go_overview.htm 
- https://golang.org/doc/install

Tidak ada komentar:

Posting Komentar