Monday, September 14, 2015

First Program

With hardly 25 keywords, it is obvious that Go will impose a bit more complicated signature for its language constructs. This becomes evident as soon as you write your first program.

package main 

import (
   "fmt",
   "runtime"
)

func main() {
   fmt.Println("Hello from", runtime.GOOS)
}

The main keyword is reserved to serve as the entry point. Go will search for a package named "main" and execute the function named "main" in it to bring your application to life.

This implies that the file name serves no purpose other than to recognise a package name at directly level. You can have a file name "obama.go" with a package named "osama" and go won't punish you.

To expose any function from the package, capitalise its name. Go is case sensitive.

The main function takes no argument and doesn't return any value (except when the application quits, and it returns 0 to OS to indicate it exited)

The compiler does have a "Println" method implementation but since compilers are written for a particular OS they dont provide a universal way of print line implementation. "fmt" package does.

go run hello-world.go command compiles the code, stores the executable in some temporary location and then runs that executable.





The need for Go?

The absence of : 
  • a richly expressive lightweight type system, 
  • a native concurrency model, and 
  • strictly regulated garbage collection....
...in most languages prompted the invention of Go. 

Go therefore stands a strong contender in being one of the most favoured language for modern multi-core computers with networking. 

Note that Go was built as a "systems" language but soon became popular to be used in other domains as well. Popularity soared due to the following facts:
 - ~25 keywords in total
 - produces compiled code
 - strongly typed
 - cross platform (doubt if this is correct usage)

Deciding on the "Go"

Came to hear about Go from a colleague and it immediately got me hooked into it. The concurrent processing capabilities of Go is crazy and I dont see why any performance oriented software would not want to be build on top of it.

Cons:

  • Ofcourse the language is still getting big(although Google has provided tools to write softwares in it), the libraries and learning resources are way more limited than for PHP or Ruby or Python or Node.
  • The language is compiled and is much like C, which means - lot of coding and a steep learning curve. The perpetrators however have managed to keep minimal syntax but it still is way off from any other scripting languages out there.
  • There maybe a bit of googling involved to stack together your web app functionality and hence it may not be an ideal fit for small to medium business who would like to put together solutions in a short span of time or for whom performance is not really the key.

Pros:
  • Unbelievable performance when compared to the rest of the technologies. The latest version boast of a whopping 63300 requests/sec. To know how better it really is, Node-Express does a meagre(when compared to GO) 8962 requests/sec. (read more about it here: https://medium.com/@tschundeee/express-vs-flask-vs-go-acc0879c2122 )
  • seems to me that it may be good fit to resolve bottlenecks in existing application which occur due to concurrency. This means a lot of jobs :)
  • Compiled and hence secure and faster by nature.

Let's Go !