Wednesday, December 31, 2014

Get Started with Golang - Google Go Programming Language

From last couple of months, I heard loads of buzz around Google Go Programming Language (Golang). I decided to give it a try and must say that it has the potential to disrupt the existing languages like Java, C# and C++. 

Moreover, with the latest release of Go 1.4 on December 2014, it is now possible to write Android apps using Go code. Would Java on Android take a backseat? It's too early to predict that but given the rivalry between Google & Java, Google would definitely want this to happen sooner than later.

Step wise installation of Google Go on Windows OS.

Go to https://golang.org/dl/
Download the required *.msi file for your Windows version. I am currently using Windows 8.1 and hence have downloaded the 64 bit architecture. The file I downloaded is highlighted in the following image. It is a 51.4 MB file. You can download the *.zip file as well but that might require manual intervention from you to set the environment.





Open the *.msi file and follow the prompt (next, next...). If I remember correctly, the *.msi file hardly took ~ 5 minutes to finish up with the installation on my Windows 8.1 machine with intel Core i7 processor.

You may encounter the following screens while installation. Default installation location for Go distribution is in your root directory i.e. C:\Go as shown in below image.




Following image, installation in progress.



Test the installation

1. Open Notepad.
2. Copy paste the following code:


package main

import "fmt"

      func main() {
      fmt.Printf("Hello world! from Basant")
 }

To see that Go supports UTF-8 characters well run a modified version of the above code in Go Playground
     
3. Save the file in C:\Go and name it as hello.go
4. Open Command prompt. ( Press windows+R and type cmd)
5. Move to Go directory as shown below and enter go run hello.go as shown below:


6. If you get the desired strings printed you are all set to sail through your new journey of Go (Golang)

Hapy New Year - 2015 & Happy Learning.
Let us Go...

Tuesday, December 30, 2014

Why Go Programming Language?

Yes, like everyone else I too had this question before starting out to explore Google's Go programming language or Golang.

What specific problems does this new language solve that are not possible to solve (efficiently) with the existing languages? If you've reached this blog, I assume, you must have already heard numerous conference talks and Youtube presentations / videos on Go Programming and they all point out Concurrent Programming as the USP of Go.

Before I share my personal experience, as why Go is required at first place, I would like to borrow the argument from Go creators and simplify them here in my own words.

The Gopher image credit goes to - Renee French's Go Gopher Mascot

Multicore processors were introduced almost a decade back and nowadays Intel's current lineup of desktop version of Core i7 extreme edition has 8 cores! and mobile version has 4 cores. Almost all the popular languages viz. Java, C# & Python etc. are too old to keep pace with this revolutionary evolution in hardware. They all were built with single core processor in mind and the support for multicore was later worked around and stitched over as a patch work. In contrast, Go is a modern language build from ground-up to efficiently utilize the advantages offered by modern days multicore CPUs. 

Yes, nowadays concurrency is hot and Go has built-in support for this feature at the language level!

A crude real life analogy could be, consider latest multicore processors as a Ferrari. Now the Ferrari has a capability to zip at a top speed of ~400 KM/Hr [~250 Miles/Hr] but will a normal city road support this speed? Unless you're driving on a motor racing circuit your Ferrari is as good as any other car. Hope you got the message :) if not please share a better analogy.

Traditionally Java, C# etc. addressed the concurrency requirements by developing thread-based codes that are quite difficult and add complexity to the application development. Go (Golang) has provided a simple and efficient way to design software that can easily scale based on the system load and underlying hardware.

As a beginner, I am yet to explore Go's concurrency aspect but I must say that I am liking the language for its minimalist design. I'll keep on updating this post as and when I learn something new about it.

I like Go for [in random order]:
  • Minimalist design.
  • Open source.
  • Compiled - [better performance].
  • Easier to deal with concurrent programming - built in asynchronous support.
  • Statically typed [less error prone as you avoid runtime type errors]
  • Go is fully garbage-collected.
  • Clean syntax, no semicolons.
  • Tidy, lesser number of brackets.
  • Only one looping construct i.e. For Loop.
  • This longer variable declaration var x string = "hello" can be shortened to x := "hello".
  • Go release 1.4 [Dec 2014] supports Android - Yes, now you can write simple Android Apps using only Go code.
  • As of Go 1.4 release Go compiler is written in C. But the team at Google, working on Go 1.5 is planning to remove all C programs from Go source tree.  Go 1.5 compiler will be bootstrapped i.e. Go will use Go to build itself.  Go version 1.4 will be used to build Go 1.5
    • Optional info: There are many programming languages where compilers have been bootstrapped, example includes, compilers for Java, Scala, Haskell etc. 
  • Many references on the web still say that Go is a System Programming Language - [i.e. it deals with operating system, device drivers & compilers etc.] - partially correct - as Go is now a general purpose programming language.
  • Microservices - Yes, they are the future of web!
  • IoT (Internet of Things) apps.
  • ---   ---

And you know what, Go is an excellent language for young school students and first time programmers.


Go is not only a good teaching language, it's an excellent one for first time programmers, including children. I want to try and outline the Go features that really stand out when you have young programmers and why I think we've ended up here.



Are you convinced enough to get started? 

If NOT 


Hope the above examples have already aroused your Golang curiosity to the Next Level.