Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Go Programming Language by Google

2,957 views

Published on

It's a natively compiled programming language by Google.

Published in: Technology
  • The Go Programming Language (Addison-Wesley Professional Computing Series) --- http://amzn.to/1UI3Avq
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Go in Action --- http://amzn.to/1VpXzUR
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Introducing Go: Build Reliable, Scalable Programs --- http://amzn.to/1T2L4hq
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Go Programming Language by Google

  1. 1. Go Introduc+on U-am Gandhi
  2. 2. 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 •  Go1 was released in March 2012
  3. 3. Why Go •  A good mix of fast compila+on, efficient execu+on and ease of programming •  combines best of sta+c language and dynamic language •  offers garbage collec+on, concurrency, scalability •  Aims to be system programming language for mul+ core machine
  4. 4. Comparison with C++, Java and Javascript C++ Java Javascript Go Typesafe ✔ ✔ ✖ ✔ Garbage Collec+on ✖ ✔ ✔ ✔ Compila+on Slow Slow NA Very Fast Concurrency ✖ ✔ ✖ ✔ Ease of programming ✖ ✔ ✔ ✔ Efficiency Highest Slow Slowest Close to C++
  5. 5. Hello World // hello.go package main import (     "fmt” ) func main() {         fmt.Println("Hello World”) }
  6. 6. Sample func+on 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)) }
  7. 7. 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
  8. 8. 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
  9. 9. Object Oriented Go •  No classes, no inheritance •  go has duck typing •  structs are used for custom types, aggrega+on •  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
  10. 10. Interface type Printer interface { Print() } type MyFloat float64 func (f MyFloat) Print() { fmt.Println(f); } func main() { var a Printer f := MyFloat(5.5) a = f }
  11. 11. Features 1/2 •  Garbage collec+on •  Concurrency •  Packages –  fmt, net, os, +me, math, zlib –  h-p://golang.org/pkg/ has the exhaus+ve 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 arithme+c
  12. 12. Features 2/2 •  Slices –  s := []int{2, 3, 5, 7, 11, 13} –  len(s) •  Maps –  var m map[string]string –  m[“index”] •  Func+on values f1 := func(x, y float64) float64 { return math.Sqrt(x*x + y*y) }
  13. 13. Concurrency •  go rou+nes –  Lightweight thread like rou+ne (may be one or more thread) •  Channels and Buffered Channel –  Useful for sync between go rou+nes –  Send and receive to channel is blocking ( no sync needed) •  Range and close –  Range used itera+ng over channel –  Close used by sender aier sending all values •  Select –  Lets gorou+ne waits on mul+ple communica+on opera+ons
  14. 14. JSON and Go type Message struct { Name string Body string Time int64 } m := Message{"Alice", "Hello", 1290090} b, err := json.Marshal(m) ----------- b is now []byte(`{"Name":"Alice","Body":"Hello","Time ":1290090}`)
  15. 15. Web Server type Hello struct{} func (h Hello) ServeHTTP( w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello TechNext !") } func main() { var h Hello http.ListenAndServe("localhost:4000", h) }
  16. 16. MongoDB Driver (mgo) •  Mgo Driver can be fetched using –  go get gopkg.in/mgo.v2 –  go get gopkg.in/mgo.v2/bson •  Sample code to connect to mongo session, err := mgo.Dial("localhost”) collection := session.DB(”mydb").C(”mycollection”) err := collection.Find(bson.M{”Name”: “XYZ”}).One(&result)
  17. 17. Go In Produc+on •  Google is using in produc+on for –  h-p://golang.org –  Vitess system for large-scale SQL installa+ons –  Download server dl.google.com •  It delivers chrome binaries and apt-get packages •  Other companies using Go in produc+on –  InfluxData –  Canonical –  Heroku –  Iron.io –  Apcera –  Docker –  h-p://go-lang.cat-v.org/organiza+ons-using-go
  18. 18. References •  FAQ h-p://golang.org/doc/faq •  Installa+on h-p://golang.org/doc/install •  Code h-p://golang.org/doc/code.html •  Videos h-p://blog.golang.org/go-videos-from-google- io-2012 •  Tour h-p://tour.golang.org/ •  Efficiency BM - JSON Benchmarks
  19. 19. References •  h-p://www.javaworld.com/ar+cle/2080935/ scrip+ng-jvm-languages/go-google-go-a- language-on-full-thro-le.html •  h-p://blog.golang.org/json-and-go •  h-p://www.drdobbs.com/open-source/geong- going-with-go •  h-p://www.drdobbs.com/open-source/why-not- go/240005062 •  h-p://www.jellolabs.com/blog/why-golang-is- ready-for-early-stage-startups.html
  20. 20. References •  h-p://stackoverflow.com/ques+ons/11462046/what- is-the-niche-of-go-lang •  h-ps://code.google.com/p/go-wiki/wiki/ SuccessStories# •  h-p://stackoverflow.com/ques+ons/12168873/cross- compile-go-on-osx •  h-p://ma-.aimoneo.net/posts/2012/11/27/real-life- concurrency-in-go/ •  h-p://www.golang-book.com/10 •  h-p://ma--welsh.blogspot.in/2013/08/rewri+ng- large-produc+on-system-in-go.html

×