go programming language by google

21
UTTAM GANDHI CONNECT WITH UTTAM ON LINKEDIN Why to go for Go

Upload: uttam-gandhi

Post on 28-Jan-2015

125 views

Category:

Technology


6 download

DESCRIPTION

It's a natively compiled programming language by Google.

TRANSCRIPT

Page 1: Go Programming Language by Google

U T T A M G A N D H I

C O N N E C T W I T H U T T A M O N L I N K E D I N

Why to go for Go

Page 2: Go Programming Language by Google

About Me

�  C, C++ Developer for last 11 years �  Hands on in Javascript, python, ruby, MongoDB �  Working with Synerzip for Since July 2011 on a C++

project

Page 3: Go Programming Language by Google

History of Go

�  Robert Griesemer, Rob Pike and Ken Thompson started the idea on Sep 21, 2007

�  It became an open source project on Nov 10, 2009

Page 4: Go Programming Language by Google

Why Go

�  Without go one has to choose between efficient compilation, efficient execution, or ease of programming

�  Go combines best of static language and dynamic language

�  Compilation is really fast �  Go is Garbage collected, concurrent execution and

communication �  Scalable, efficient and productive ( C like) �  Go aims to be system programming language for multi

core machine

Page 5: Go Programming Language by Google

Comparison with C++, Java and Javascript

C++ Java Javascript Go Typesafe ✔ ✔ ✖ ✔ Garbage Collection

Compilation Slow Slow NA Very Fast Concurrency ✖ ✔ ✖ ✔ Ease of programming

✔ ✔

Efficiency Highest Slow Slowest Close to C++

Page 6: Go Programming Language by Google

Hello World

// hello.go!package main!import (!    "fmt”!)!func main() { !        fmt.Println("Hello World”)!}!

Page 7: Go Programming Language by Google

Sample function

package main!Import “fmt”!func split(sum int) (x, y int) {! x = sum * 4 / 9! y = sum - x! return!}!func main() {! var x, y, z int! fmt.Println(x,y,z)! fmt.Println(split(17))!}!

Page 8: Go Programming Language by Google

How to Write Go Code 1/2

�  Go tool is designed to work with open source code maintained in public repositories

�  Workspace ¡  src ¡  pkg ¡  bin

�  export GOPATH=$HOME/go!�  go install hello!

Page 9: Go Programming Language by Google

How to Write Go Code 2/2

�  go install sum (create and put lib pkg)!�  go install usinglib !�  go get code.google.com/p/go.example/hello!

�  go test sum!

Page 10: Go Programming Language by Google

Object Oriented Go

�  No classes, no inheritance �  go has duck typing �  structs are used for custom types, aggregation �  Interfaces, abstract type has methods �  Any custom type having same methods as interface

follows that (and/or other) interface �  Interface{}, empty interface is like void in C or

Object in Java

Page 11: Go Programming Language by Google

interface

package main!import (! "fmt"!)!type Printer interface {! Print()!}!func (f MyFloat) Print() {!

!fmt.Println(f);!}!func main() {! var a Printer ! f := MyFloat(5.5)! a = f!

Page 12: Go Programming Language by Google

Features 1/2

�  Garbage collection �  Concurrency �  Packages

¡  fmt, net, os, time, math, zlib ¡  http://golang.org/pkg/ has the exhaustive list

�  Types ¡  bool, int, int8, int16, int32, int64, uint …, byte, float32,float64,

complex64, complex128 ¡  const

�  For loop only �  struct, access fields using dot �  Pointer but no pointer arithmetic

Page 13: Go Programming Language by Google

Features 2/2

�  Slices (array) http://tour.golang.org/#31 �  Maps http://tour.golang.org/#39 �  Function closures http://tour.golang.org/#43 �  Struct methods http://tour.golang.org/#50

¡  Methods cannot be defined on basic types �  Interfaces http://tour.golang.org/#53 �  Error http://tour.golang.org/#55

Page 14: Go Programming Language by Google

Concurrency

�  go routines ¡  Lightweight thread like routine (may be one or more thread)

�  Channels and Buffered Channel ¡  Useful for sync between go routines ¡  Send and receive to channel is blocking ( no sync needed)

�  Range and close ¡  Range used iterating over channel ¡  Close used by sender after sending all values

�  Select ¡  Lets goroutine waits on multiple communication operations

Page 15: Go Programming Language by Google

JSON and Go

type Message struct {! Name string! Body string! Time int64!}!m := Message{"Alice", "Hello", 1294706395881547000}!b, err := json.Marshal(m)!b == []byte(`{"Name":"Alice","Body":"Hello","Time":1294706395881547000}`)!

Page 16: Go Programming Language by Google

Web Server

Creating a webserver is child’s play in Go, (if the child knows programming J A sample is available here

Web Server -- http://tour.golang.org/#59

Page 17: Go Programming Language by Google

Go In Production

�  Google is using in production for ¡  http://golang.org ¡  Vitess system for large-scale SQL installations ¡  Download server dl.google.com

÷  It delivers chrome binaries and apt-get packages �  Other companies using Go in production

¡  BBC Worldwide ¡  Canonical ¡  Heroku

÷  Replaced web services written ROR to GO ¡  Iron.io

¢  Cloud application services, replaced ROR to GO ¡  Nokia ¡  SoundCloud ¡  http://go-lang.cat-v.org/organizations-using-go

Page 18: Go Programming Language by Google

My Opinion About Go

�  In my opinion Go is very useful for server side programming and command-line tools. It’s concurrency feature makes it stands out from rest of the programming languages.

�  The programs written with Go will be less complex than C++, making it easier to maintain.

Page 19: Go Programming Language by Google

References

�  FAQ http://golang.org/doc/faq �  Installation http://golang.org/doc/install �  Code http://golang.org/doc/code.html �  Videos

http://blog.golang.org/go-videos-from-google-io-2012

�  Tour http://tour.golang.org/ �  Efficiency BM - JSON Benchmarks

Page 20: Go Programming Language by Google

References

�  http://www.javaworld.com/article/2080935/scripting-jvm-languages/go-google-go-a-language-on-full-throttle.html

�  http://blog.golang.org/json-and-go �  http://www.drdobbs.com/open-source/getting-

going-with-go �  http://www.drdobbs.com/open-source/why-not-go/

240005062 �  http://www.jellolabs.com/blog/why-golang-is-

ready-for-early-stage-startups.html

Page 21: Go Programming Language by Google

References

�  http://stackoverflow.com/questions/11462046/what-is-the-niche-of-go-lang

�  https://code.google.com/p/go-wiki/wiki/SuccessStories#

�  http://stackoverflow.com/questions/12168873/cross-compile-go-on-osx

�  http://matt.aimonetti.net/posts/2012/11/27/real-life-concurrency-in-go/

�  http://www.golang-book.com/10 �  http://matt-welsh.blogspot.in/2013/08/rewriting-large-

production-system-in-go.html