Go

264 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
264
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Go

  1. 1. WEB Programming telecom, finance, el ectronics etc. j2ee, gwt, android, d art, javascript, etc . Senior Developer at i2i systems Mobile Programming Ali PARMAKSIZ @parmaksiza
  2. 2. What? Why? When?
  3. 3. Some Companies ..... Canonical, BBC Heroku, CloudFoundry SoundCloud, Mob Rules Games, Carbon Games Google 
  4. 4. IntelliJ Eclipse Netbeans LiteIDE TextMate Komodo
  5. 5. Some Data Types... Boolean, String Numeric Array, Slice, Map Channel, Interface, Struct, Pointer, Function
  6. 6. func variables() (variableResult int) { //Explicit type declartion var var1, var2, var3 int = 1, 2, 3 //The type is implied var4, var5, var6 := 4, 5, 6 //variableResult is a named //result parameter variableResult = var1 + var2 + var3 + var4 + var5 + var6 type vertex struct { x, y int } Struct //Don't need to return anything since variableResult was //assigned above. return } Variables type vertex struct { x, y int } func pointers() { vertexOrignal := vertex{1, 2} //This is going to make a copy of the original. vertexCopy := vertexOrignal vertexCopy.x = 3 vertexCopy.y = 4 //vertexOrignal.x, vertexOrignal.y will remain //unchange since it mutated the //copy //This will assign a pointer to //vertexReference instead of //copying the //value. vertexReference := &vertexOrignal vertexCopy.x = 3 vertexCopy.y = 4 //vertexOrignal.x, vertexOrignal.y will change //since it mutated the the pointer. } Pointers SLICES
  7. 7. func sliceLength() { //Create slice with length of five sliceWithLength := make([]vertex, 5) for i := 0; i < len(sliceWithLength); i++ { sliceWithLength[i] = vertex{i, i + 1} } } func sliceNil() { //Create a nil slice. Used in the cases where you get //the size at runtime. var sliceWithNil []vertex for i := 0; i < 5; i++ { sliceWithNil = append(sliceWithNil, vertex{i, i + 1}) } } func mutatingSlices() { // This function mutates slices sliceVertices := make([]vertex, 5) for i := 0; i < len(sliceVertices); i++ { sliceVertices[i] = vertex{i, i + 1} } //Won't change the //value in the slice for _, vertex := range vertices { vertex.x++ vertex.y++ } //Will change the value in the slice for i := 0; i < len(vertices); i++ { vertex := &vertices[i] vertex.x++ vertex.y++ } } SLICES
  8. 8. elements := make(map[string]string) elements["H"] = "Hydrogen" elements["He"] = "Helium" elements["Li"] = "Lithium" elements["Be"] = "Beryllium" elements["B"] = "Boron" elements["C"] = "Carbon“ elements["N"] = "Nitrogen" elements["O"] = "Oxygen“ elements["F"] = "Fluorine" elements["Ne"] = "Neon"} func main() { elements := map[string]map[string]string{ "H": map[string]string{ "name":"Hydrogen", "state":"gas", }, "He": map[string]string{ "name":"Helium", "state":"gas", }, "Li": map[string]string{ "name":"Lithium", "state":"solid", }, "Be": map[string]string{ "name":"Beryllium", "state":"solid", }, "B": map[string]string{ "name":"Boron", "state":"solid", }, "C": map[string]string{ "name":"Carbon", "state":"solid", }, "N": map[string]string{ "name":"Nitrogen", "state":"gas", }, "O": map[string]string{ "name":"Oxygen", "state":"gas", }, "F": map[string]string{ "name":"Fluorine", "state":"gas", }, "Ne": map[string]string{ "name":"Neon", "state":"gas", }, } if el, ok := elements["Li"]; ok { fmt.Println(el["name"], el["state"]) } } MAPS
  9. 9. Go's philosophically, to concurrency differs from the traditional use of threads and shared memory can be summarized as
  10. 10. Concurreny model in GO Channels Go routines So what is channels and Go routines ?
  11. 11. Coming .......Go routines
  12. 12. What is a channel ?
  13. 13. //Declaring and initializing.. var c chan int c= make (chan int) //or c:=make(chan int) //Send value to channel c<-1 //get value from channel value<-c
  14. 14. As a result of channel and go routines ....
  15. 15. Set it up to make 5 request a second and stop after 15 request were made. It's passing both web services 40 for the number of iterations to do, a CPU-intensive taking about 2 seconds to process Node.js starts off by finishing the first four request simultaneously in about 4 seconds. Then it takes 3 seconds to finish one request at a time. It takes a total of nearly 34 seconds to complete all the requests Go takes 2 seconds to finish 2 requests, another 4 to do 4 more and then down to 2 again and so on. It finishes all of them in about 6.5 seconds See more at: https://c2fo.com/insights/exploring-googles-go-programming-language/

×