Hi All!

In Summer 2016, I had an opportunity to play with Golang during my internship. The language is pretty awesome. Recently couple of days back, I came across 24daysofrust blog post, which in turn inspired from 24 Days of Hackage blog post. I thought to give it a go.

I’m planning to try out my version of 24-Days-Of-GoLang from Tuesday(..soon as I’m done with my finals :D). I will keep updating this post, and record my progress. When I’m done, I will change it a sort of tutorial for Golang.

Peace!


Prep (12/20/2016)

To keep things clean and organized, I have created another post to prepare Go development environment. It includes instructions for both on Linux & Windows platform. Checkout Golang Setup post.

Timeline

I’m planning to follow A tour of Go tutorials. The tutorial is divided into 5 sections, and I will spend 4 days exploring each of these sections.

Tours Start Date End Date Days
Packages,Variables and Functions 12/24/2016 12/28/2016 4
Flow control statements 12/29/2016 1/1/2017 8
Struct,slices,maps 1/2/2017 1/5/2017 12
Methods & Interfaces 1/6/2017 1/9/2017 16
Concurrency 1/10/2017 1/13/2017 20
Additional Practice 1/14/2017 1/17/2017 24

Tour 1 (12/24/2016) : The Slow start (Packages, Variables and Functions)

Go is mostly inspired from C language. It is a compiled and statically typed . The ‘go’ tool generates a temporary (OS specific) executable of go application. Unlike Java, Go has no separate virtual machine to run the application. Instead the runtime is statically linked with the application (sometimes compiled version is larger in size than the source code).

Go OOP: In Go we can define interfaces, with custom types. Types can have member methods & Struct data structure can have member fields. But Go has no inheritance, operator overloading ,autoboxing or exception handling system (also semicolons are optional).

Like any other programming language tutorial, the first program would be ‘Hello, World!’.

package main

// factored import statements
import(
	"fmt"
	"math"
	"math/rand"
)

// functions with 2 arguments
func add(x int, y int) int{
	return x+y
}

// if parameters share the same type, put it only at the last
func sub(x,y int)int{
	return x-y
}

// multiple returns
func swap(x,y int)(int,int){
	return y,x
}

// the code starts here
func main(){
	fmt.Println("Hello Go! ")
	/* Exported name : Pi
	   In Go, any name with a CAPITAL letter, following the package name
	   is an exported name.
	*/
	fmt.Println("Random number is:",rand.Intn(10))
	fmt.Println(math.Pi)
	fmt.Println("Addition: ",add(2,3))
	fmt.Println("Substraction: " , sub(5,2))
	// multi value swaps. This reminds me of Python swap function
	a,b :=swap(5,2)
	fmt.Println("Swap: a= ",a," and b= ",b)
}

Day 1 (12/22/2016)

.. coming up soon


Ashish

man + machine > problem