SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Go	
  ahead,	
  make	
  my	
  day.	
  
Intro	
  to	
  Go	
  programming	
  language	
  
Me	
  
@torkale	
  
	
  
h8p://github.com/torkale	
  
	
  
torkale[at]gmail	
  
Why	
  Go?	
  
Challenge	
  

Safety	
  &	
  
Performance	
   Expressiveness	
  
&	
  Convenience	
  
Mascot	
  
Performance	
  
Type	
  safety	
  
Concurrency	
  
Scalability	
  
ProducKvity	
  

AL	
  
Respected	
  Parents	
  
Ken	
  Thompson	
  
Unix,	
  B,	
  UTF-­‐8,	
  Plan	
  9	
  
	
  
	
  
Rob	
  Pike	
  
Plan	
  9,	
  UTF-­‐8,	
  Limbo,	
  Unix	
  team	
  
The	
  Unix	
  Programming	
  Environment	
  
The	
  PracKce	
  of	
  Programming	
  
History	
  

Rob	
  Pike	
  

Ken	
  Thompson	
  

Robert	
  Griesmer	
  

Start	
  
Late	
  2007	
  

Public	
  	
  
2009	
  

Go	
  1.0	
  
March	
  2012	
  

Go	
  1.1	
  
May	
  2013	
  
Hello	
  
package	
  main	
  
	
  
import	
  "fmt"	
  
	
  
func	
  greet()	
  {	
  
	
  fmt.Println("Hello,	
  I	
  love	
  you,	
  won’t	
  you	
  tell	
  me	
  your	
  name?”)	
  
}	
  
	
  
func	
  main()	
  {	
  
	
  greet()	
  
}	
  
Web	
  Server	
  
package	
  main	
  
	
  
import	
  (	
  
	
  	
  	
  	
  "fmt"	
  
	
  	
  	
  	
  "net/h8p"	
  
)	
  
	
  
func	
  handler(w	
  h8p.ResponseWriter,	
  r	
  *h8p.Request)	
  {	
  
	
  	
  	
  	
  fmt.Fprine(w,	
  ”Request	
  from	
  %s",	
  r.URL.Path[1:])	
  
}	
  
	
  
func	
  main()	
  {	
  
	
  	
  	
  	
  h8p.HandleFunc("/",	
  handler)	
  
	
  	
  	
  	
  h8p.ListenAndServe(":8080",	
  nil)	
  
}	
  
Basic	
  types	
  
DeclaraKons	
  
CondiKons	
  
Loops	
  
Slice	
  
Map	
  

BASICS	
  
Basic	
  Types	
  
bool	
  
	
  
string	
  
	
  
int	
  	
  int8	
  	
  int16	
  	
  int32	
  	
  int64	
  
uint	
  uint8	
  uint16	
  uint32	
  uint64	
  uintptr	
  
	
  
byte	
  //	
  alias	
  for	
  uint8	
  
	
  
rune	
  //	
  alias	
  for	
  int32	
  
	
  	
  	
  	
  	
  //	
  represents	
  a	
  Unicode	
  code	
  point	
  
	
  
float32	
  float64	
  
	
  
complex64	
  complex128	
  
DeclaraKons	
  
var	
  i	
  int	
  
i	
  =	
  getInteger()	
  
	
  
j	
  :=	
  getInteger()	
  
	
  
value,	
  err	
  :=	
  getValueOrError()	
  
	
  
value2,	
  _	
  :=	
  getValueOrError()	
  
CondiKons	
  
var	
  even	
  bool	
  
	
  
if	
  x%2	
  ==	
  0	
  {	
  
	
  	
  	
  	
  even	
  =	
  true	
  
}	
  
	
  
if	
  x%2	
  ==	
  0	
  {	
  
	
  	
  	
  	
  even	
  =	
  true	
  
}	
  else	
  {	
  
	
  	
  	
  	
  even	
  =	
  false	
  
}	
  
	
  
if	
  mod	
  :=	
  x%2;	
  mod	
  ==	
  0	
  {	
  
	
  	
  	
  	
  even	
  =	
  true	
  
}	
  
Loops	
  
factorial	
  :=	
  1	
  
for	
  i	
  :=	
  2;	
  i	
  <=	
  num;	
  i++	
  {	
  
	
  	
  	
  	
  factorial	
  *=	
  i	
  
}	
  
	
  
nextPowerOf2	
  :=	
  1	
  
for	
  nextPowerOf2	
  <	
  num	
  {	
  
	
  	
  	
  	
  nextPowerOf2	
  *=2	
  
}	
  
	
  
for	
  {	
  
	
  	
  	
  	
  //	
  Forever	
  
}	
  
Slice	
  
primes	
  :=	
  []int{2,	
  3,	
  5,	
  7,	
  11,	
  13}	
  
	
  
fmt.Println("primes[1:4]	
  ==",	
  primes[1:4])	
  
	
  
zeroes	
  :=	
  make([]int,	
  5)	
  
fmt.Println("zeroes	
  ==",	
  zeroes)	
  
	
  
for	
  i,	
  v	
  :=	
  range	
  primes	
  {	
  
	
  	
  	
  	
  	
  fmt.Prine("(%d)	
  =	
  %dn",	
  i,	
  v)	
  
}	
  
for	
  _,	
  v	
  :=	
  range	
  primes	
  {	
  
	
  	
  	
  	
  	
  fmt.Prine("%dn",	
  v)	
  
}	
  
Map	
  
m	
  :=	
  make(map[string]int)	
  
m["Ten"]	
  =	
  10	
  
fmt.Println(m)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
capitals	
  :=	
  map[string]string{	
  
	
  	
  "Jerusalem":	
  "Israel",	
  
	
  	
  "Paris":	
  "France",	
  
	
  	
  "London":	
  "UK",	
  
}	
  
fmt.Println(capitals)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
delete(capitals,	
  "London")	
  
v,	
  present	
  :=	
  capitals["London"]	
  
fmt.Println("The	
  capital:",	
  v,	
  "Present?",	
  present)	
  
Custom	
  types	
  
Extension	
  via	
  composiKon	
  
Methods	
  

TYPES	
  
Custom	
  Types	
  
type	
  Name	
  string	
  
	
  
type	
  Person	
  struct	
  {	
  
	
  	
  	
  	
  first	
  Name	
  
	
  	
  	
  	
  last	
  	
  Name	
  
}	
  
	
  
type	
  Hero	
  struct	
  {	
  
	
  	
  	
  	
  Person	
  
	
  	
  	
  	
  power	
  string	
  
}	
  
	
  
type	
  Crowd	
  struct	
  {	
  
	
  	
  	
  	
  people	
  []Person	
  
}	
  
Methods	
  
func	
  (dude	
  Person)	
  FullName()	
  string	
  {	
  
	
  	
  	
  	
  return	
  fmt.Sprine("%s	
  %s",	
  dude.first,	
  dude.last)	
  
}	
  
	
  
func	
  (dude	
  Person)	
  SetFirst(name	
  Name)	
  {	
  
	
  	
  	
  	
  dude.first	
  =	
  name	
  
}	
  
	
  
func	
  (h	
  *Hero)	
  ToString()	
  string	
  {	
  
	
  	
  	
  	
  return	
  fmt.Sprine("Name:	
  %s	
  Power:	
  %s",	
  h.FullName(),	
  h.power)	
  
}	
  
	
  
func	
  NewPerson(f,	
  l	
  Name)	
  Person	
  {	
  
	
  	
  	
  	
  return	
  Person{f,	
  l}	
  
}	
  
AbstracKon	
  
Duck	
  typing	
  
Signatures	
  
Implicit	
  

INTERFACES	
  
interfaces	
  
type	
  Talker	
  interface	
  {	
  
	
  	
  	
  	
  Talk()	
  string	
  
}	
  
	
  
func	
  (dude	
  Person)	
  Talk()	
  string	
  {	
  
	
  	
  	
  	
  return	
  fmt.Sprine("My	
  name	
  is	
  %s",	
  dude.FullName())	
  
}	
  
	
  
func	
  MakeSomeoneTalk(talker	
  Talker)	
  string	
  {	
  
	
  	
  	
  	
  return	
  talker.Talk()	
  
}	
  
	
  
func	
  interfaces()	
  {	
  
	
  	
  	
  	
  fmt.Println(MakeSomeoneTalk(NewPerson("Robert",	
  "de	
  Niro")))	
  
}	
  
Higher-­‐order	
  funcKons	
  
Custom	
  funcKon	
  types	
  
Closures	
  
MulKple	
  return	
  values	
  

FUNCTIONS	
  
FuncKons	
  
type	
  PersonAcKon	
  func(some	
  Person)	
  Name	
  
	
  
func	
  (crowd	
  Crowd)	
  ConcatPersonAcKons(acKon	
  PersonAcKon)	
  string	
  {	
  
	
  	
  	
  	
  var	
  result	
  string	
  
	
  	
  	
  	
  for	
  _,	
  dude	
  :=	
  range	
  crowd.people	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  result	
  =	
  fmt.Sprine("%s	
  %s",	
  result,	
  acKon(dude))	
  
	
  	
  	
  	
  }	
  
	
  	
  	
  	
  return	
  result	
  
}	
  
	
  
func	
  AllLastNames(crowd	
  Crowd)	
  string	
  {	
  
	
  	
  	
  	
  return	
  crowd.ConcatPersonAcKons(func(dude	
  Person)	
  Name	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  dude.last	
  
	
  	
  	
  	
  })	
  
}	
  
defer	
  
func	
  MeasureStart(label	
  string)	
  (string,	
  Kme.Time)	
  {	
  
	
  	
  	
  	
  return	
  label,	
  Kme.Now()	
  
}	
  
	
  
func	
  Measure(label	
  string,	
  startTime	
  Kme.Time)	
  {	
  
	
  	
  	
  	
  duraKon	
  :=	
  Kme.Now().Sub(startTime)	
  
	
  	
  	
  	
  fmt.Println(label,	
  "ComputaKon	
  took",	
  duraKon)	
  
}	
  
	
  
func	
  benchmark()	
  {	
  
	
  	
  	
  	
  defer	
  Measure(MeasureStart("benchmark()"))	
  
	
  	
  	
  	
  Kme.Sleep(Kme.Second)	
  
}	
  
CSP	
  
go-­‐rouKne	
  
channels	
  
select	
  

CONCURRENCY	
  
CommunicaKng	
  SequenKal	
  Processes	
  	
  
“Do	
  not	
  communicate	
  by	
  sharing	
  memory;	
  
instead	
  share	
  memory	
  by	
  communicaKng”	
  
go	
  rouKnes	
  
var	
  a	
  string	
  
	
  
func	
  Init()	
  {	
  
	
  	
  a	
  =	
  "finally	
  started"	
  
	
  	
  return	
  
}	
  
	
  
func	
  doSomethingElse()	
  {	
  
	
  	
  //	
  …	
  
}	
  
	
  
func	
  Simple()	
  string{	
  
	
  	
  go	
  Init()	
  
	
  	
  doSomethingElse()	
  
	
  	
  return	
  a	
  
}	
  
tradiKonal	
  
var	
  (	
  
	
  	
  a	
  string	
  
	
  	
  wg	
  sync.WaitGroup	
  
)	
  
	
  
func	
  Init()	
  {	
  
	
  	
  defer	
  wg.Done()	
  
	
  	
  a	
  =	
  "finally	
  started"	
  
}	
  
	
  
func	
  Simple()	
  string{	
  
	
  	
  wg.Add(1)	
  
	
  	
  go	
  Init()	
  
	
  	
  wg.Wait()	
  
	
  	
  //	
  do	
  something	
  else	
  
	
  	
  return	
  a	
  
}	
  
channel	
  
package	
  channel	
  
	
  
var	
  (	
  
	
  	
  a	
  string	
  
	
  	
  ready	
  chan	
  bool	
  
)	
  
	
  
func	
  Init()	
  {	
  
	
  	
  a	
  =	
  "finally	
  started"	
  
	
  	
  ready	
  <-­‐	
  true	
  
}	
  
	
  
func	
  Simple()	
  string{	
  
	
  	
  ready	
  =	
  make(chan	
  bool)	
  
	
  	
  go	
  Init()	
  
	
  	
  	
  //	
  do	
  something	
  else	
  
	
  	
  <-­‐ready	
  
	
  	
  return	
  a	
  
}	
  
Producer	
  /	
  Consumer	
  
func	
  producer(c	
  chan	
  string){	
  
	
  	
  defer	
  close(c)	
  
	
  	
  for	
  {	
  
	
  	
  	
  	
  work	
  :=	
  getWork()	
  
	
  	
  	
  	
  c	
  <-­‐	
  work	
  
	
  	
  }	
  
}	
  	
  
	
  
func	
  consumer(c	
  chan	
  string)	
  {	
  
	
  	
  for	
  msg	
  :=	
  range	
  c	
  {	
  
	
  	
  	
  	
  	
  	
  process(msg)	
  
	
  	
  }	
  
}	
  
	
  
func	
  ProducerConsumer()	
  {	
  
	
  	
  c	
  :=	
  make(chan	
  string)	
  
	
  	
  go	
  producer(c)	
  
	
  	
  consumer(c)	
  
}	
  
Producer	
  /	
  Consumer	
  
func	
  producer(c	
  chan	
  string){	
  
	
  	
  defer	
  close(c)	
  
	
  	
  for	
  {	
  
	
  	
  	
  	
  work	
  :=	
  getWork()	
  
	
  	
  	
  	
  c	
  <-­‐	
  work	
  
	
  	
  }	
  
}	
  	
  
	
  
func	
  consumer(c	
  chan	
  string,	
  abort	
  <-­‐chan	
  Kme.Time)	
  {	
  
	
  	
  for	
  {	
  
	
  	
  	
  	
  select	
  {	
  
	
  	
  	
  	
  case	
  msg	
  :=	
  <-­‐c:	
  
	
  	
  	
  	
  	
  	
  process(msg)	
  
	
  	
  	
  	
  case	
  <-­‐	
  abort:	
  
	
  	
  	
  	
  	
  	
  return	
  
	
  	
  	
  	
  }	
  
	
  	
  }	
  
}	
  
	
  
func	
  ProducerConsumer()	
  {	
  
	
  	
  c	
  :=	
  make(chan	
  string)	
  
	
  	
  go	
  producer(c)	
  
	
  	
  	
  
	
  	
  abort	
  :=	
  Kme.A|er(2*Kme.Second)	
  
	
  	
  consumer(c,	
  abort)	
  
}	
  
Barber	
  Shop	
  
Var	
  	
  
	
  	
  seats	
  =	
  make(chan	
  Customer,	
  2)	
  
	
  	
  customers	
  :=	
  []Customer{	
  "Al",	
  "Bob",	
  "Chad",	
  "Dave"	
  }	
  
)	
  
	
  
func	
  barber()	
  {	
  
	
  	
  for	
  {	
  
	
  	
  	
  	
  c	
  :=	
  <-­‐seats	
  
	
  	
  	
  	
  fmt.Println("Barber	
  shaving",	
  c)	
  
	
  	
  }	
  
}	
  
	
  
func	
  (c	
  Customer)	
  enter()	
  {	
  
	
  	
  select	
  {	
  
	
  	
  case	
  seats	
  <-­‐	
  c:	
  
	
  	
  default:	
  
	
  	
  	
  	
  fmt.Println("Customer",	
  c,	
  "Leaves")	
  
	
  	
  }	
  
}	
  
	
  
func	
  BarberShop()	
  {	
  
	
  	
  go	
  barber()	
  
	
  	
  for	
  _,	
  c	
  :=	
  range	
  customers	
  {	
  
	
  	
  	
  	
  go	
  c.enter()	
  
	
  	
  }	
  
}	
  
version	
  
build	
  
test	
  
get	
  

install 	
  	
  
fmt	
  
…	
  
build	
  -­‐-­‐race	
  (1.1+)	
  

GO	
  COMMAND	
  
h8p://golang.org/	
  
h8p://tour.golang.org/	
  
h8ps://code.google.com/p/go-­‐wiki/wiki/Projects	
  
h8ps://groups.google.com/forum/#!forum/golang-­‐nuts	
  
#go-­‐nuts	
  on	
  irc.freenode.net	
  
h8ps://www.facebook.com/groups/golanggonuts	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. ExperienceMike Fogus
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.Mike Fogus
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveEleanor McHugh
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184Mahmoud Samir Fayed
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in GolangOliver N
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collectionsMyeongin Woo
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftGiordano Scalzo
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes
 
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181Mahmoud Samir Fayed
 

Was ist angesagt? (20)

Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. Experience
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
Kotlin coroutines
Kotlin coroutines Kotlin coroutines
Kotlin coroutines
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's Perspective
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
Corona sdk
Corona sdkCorona sdk
Corona sdk
 
Kotlin standard
Kotlin standardKotlin standard
Kotlin standard
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
 
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181
 

Ähnlich wie Go ahead, make my day

Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of GoFrank Müller
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionHans Höchtl
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)Ishin Vin
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Codemotion
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency명신 김
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 

Ähnlich wie Go ahead, make my day (20)

Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
Beauty and Power of Go
Beauty and Power of GoBeauty and Power of Go
Beauty and Power of Go
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Fun with functions
Fun with functionsFun with functions
Fun with functions
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Monadologie
MonadologieMonadologie
Monadologie
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Let's golang
Let's golangLet's golang
Let's golang
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 

Kürzlich hochgeladen

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Go ahead, make my day

  • 1. Go  ahead,  make  my  day.   Intro  to  Go  programming  language  
  • 2. Me   @torkale     h8p://github.com/torkale     torkale[at]gmail  
  • 4. Challenge   Safety  &   Performance   Expressiveness   &  Convenience  
  • 5. Mascot   Performance   Type  safety   Concurrency   Scalability   ProducKvity   AL  
  • 6. Respected  Parents   Ken  Thompson   Unix,  B,  UTF-­‐8,  Plan  9       Rob  Pike   Plan  9,  UTF-­‐8,  Limbo,  Unix  team   The  Unix  Programming  Environment   The  PracKce  of  Programming  
  • 7. History   Rob  Pike   Ken  Thompson   Robert  Griesmer   Start   Late  2007   Public     2009   Go  1.0   March  2012   Go  1.1   May  2013  
  • 8.
  • 9. Hello   package  main     import  "fmt"     func  greet()  {    fmt.Println("Hello,  I  love  you,  won’t  you  tell  me  your  name?”)   }     func  main()  {    greet()   }  
  • 10. Web  Server   package  main     import  (          "fmt"          "net/h8p"   )     func  handler(w  h8p.ResponseWriter,  r  *h8p.Request)  {          fmt.Fprine(w,  ”Request  from  %s",  r.URL.Path[1:])   }     func  main()  {          h8p.HandleFunc("/",  handler)          h8p.ListenAndServe(":8080",  nil)   }  
  • 11. Basic  types   DeclaraKons   CondiKons   Loops   Slice   Map   BASICS  
  • 12. Basic  Types   bool     string     int    int8    int16    int32    int64   uint  uint8  uint16  uint32  uint64  uintptr     byte  //  alias  for  uint8     rune  //  alias  for  int32            //  represents  a  Unicode  code  point     float32  float64     complex64  complex128  
  • 13. DeclaraKons   var  i  int   i  =  getInteger()     j  :=  getInteger()     value,  err  :=  getValueOrError()     value2,  _  :=  getValueOrError()  
  • 14. CondiKons   var  even  bool     if  x%2  ==  0  {          even  =  true   }     if  x%2  ==  0  {          even  =  true   }  else  {          even  =  false   }     if  mod  :=  x%2;  mod  ==  0  {          even  =  true   }  
  • 15. Loops   factorial  :=  1   for  i  :=  2;  i  <=  num;  i++  {          factorial  *=  i   }     nextPowerOf2  :=  1   for  nextPowerOf2  <  num  {          nextPowerOf2  *=2   }     for  {          //  Forever   }  
  • 16. Slice   primes  :=  []int{2,  3,  5,  7,  11,  13}     fmt.Println("primes[1:4]  ==",  primes[1:4])     zeroes  :=  make([]int,  5)   fmt.Println("zeroes  ==",  zeroes)     for  i,  v  :=  range  primes  {            fmt.Prine("(%d)  =  %dn",  i,  v)   }   for  _,  v  :=  range  primes  {            fmt.Prine("%dn",  v)   }  
  • 17. Map   m  :=  make(map[string]int)   m["Ten"]  =  10   fmt.Println(m)                                                                                                 capitals  :=  map[string]string{      "Jerusalem":  "Israel",      "Paris":  "France",      "London":  "UK",   }   fmt.Println(capitals)                                                                                                 delete(capitals,  "London")   v,  present  :=  capitals["London"]   fmt.Println("The  capital:",  v,  "Present?",  present)  
  • 18. Custom  types   Extension  via  composiKon   Methods   TYPES  
  • 19. Custom  Types   type  Name  string     type  Person  struct  {          first  Name          last    Name   }     type  Hero  struct  {          Person          power  string   }     type  Crowd  struct  {          people  []Person   }  
  • 20. Methods   func  (dude  Person)  FullName()  string  {          return  fmt.Sprine("%s  %s",  dude.first,  dude.last)   }     func  (dude  Person)  SetFirst(name  Name)  {          dude.first  =  name   }     func  (h  *Hero)  ToString()  string  {          return  fmt.Sprine("Name:  %s  Power:  %s",  h.FullName(),  h.power)   }     func  NewPerson(f,  l  Name)  Person  {          return  Person{f,  l}   }  
  • 21. AbstracKon   Duck  typing   Signatures   Implicit   INTERFACES  
  • 22. interfaces   type  Talker  interface  {          Talk()  string   }     func  (dude  Person)  Talk()  string  {          return  fmt.Sprine("My  name  is  %s",  dude.FullName())   }     func  MakeSomeoneTalk(talker  Talker)  string  {          return  talker.Talk()   }     func  interfaces()  {          fmt.Println(MakeSomeoneTalk(NewPerson("Robert",  "de  Niro")))   }  
  • 23. Higher-­‐order  funcKons   Custom  funcKon  types   Closures   MulKple  return  values   FUNCTIONS  
  • 24. FuncKons   type  PersonAcKon  func(some  Person)  Name     func  (crowd  Crowd)  ConcatPersonAcKons(acKon  PersonAcKon)  string  {          var  result  string          for  _,  dude  :=  range  crowd.people  {                  result  =  fmt.Sprine("%s  %s",  result,  acKon(dude))          }          return  result   }     func  AllLastNames(crowd  Crowd)  string  {          return  crowd.ConcatPersonAcKons(func(dude  Person)  Name  {                  return  dude.last          })   }  
  • 25. defer   func  MeasureStart(label  string)  (string,  Kme.Time)  {          return  label,  Kme.Now()   }     func  Measure(label  string,  startTime  Kme.Time)  {          duraKon  :=  Kme.Now().Sub(startTime)          fmt.Println(label,  "ComputaKon  took",  duraKon)   }     func  benchmark()  {          defer  Measure(MeasureStart("benchmark()"))          Kme.Sleep(Kme.Second)   }  
  • 26. CSP   go-­‐rouKne   channels   select   CONCURRENCY  
  • 27. CommunicaKng  SequenKal  Processes     “Do  not  communicate  by  sharing  memory;   instead  share  memory  by  communicaKng”  
  • 28. go  rouKnes   var  a  string     func  Init()  {      a  =  "finally  started"      return   }     func  doSomethingElse()  {      //  …   }     func  Simple()  string{      go  Init()      doSomethingElse()      return  a   }  
  • 29. tradiKonal   var  (      a  string      wg  sync.WaitGroup   )     func  Init()  {      defer  wg.Done()      a  =  "finally  started"   }     func  Simple()  string{      wg.Add(1)      go  Init()      wg.Wait()      //  do  something  else      return  a   }  
  • 30. channel   package  channel     var  (      a  string      ready  chan  bool   )     func  Init()  {      a  =  "finally  started"      ready  <-­‐  true   }     func  Simple()  string{      ready  =  make(chan  bool)      go  Init()        //  do  something  else      <-­‐ready      return  a   }  
  • 31. Producer  /  Consumer   func  producer(c  chan  string){      defer  close(c)      for  {          work  :=  getWork()          c  <-­‐  work      }   }       func  consumer(c  chan  string)  {      for  msg  :=  range  c  {              process(msg)      }   }     func  ProducerConsumer()  {      c  :=  make(chan  string)      go  producer(c)      consumer(c)   }  
  • 32. Producer  /  Consumer   func  producer(c  chan  string){      defer  close(c)      for  {          work  :=  getWork()          c  <-­‐  work      }   }       func  consumer(c  chan  string,  abort  <-­‐chan  Kme.Time)  {      for  {          select  {          case  msg  :=  <-­‐c:              process(msg)          case  <-­‐  abort:              return          }      }   }     func  ProducerConsumer()  {      c  :=  make(chan  string)      go  producer(c)            abort  :=  Kme.A|er(2*Kme.Second)      consumer(c,  abort)   }  
  • 33. Barber  Shop   Var        seats  =  make(chan  Customer,  2)      customers  :=  []Customer{  "Al",  "Bob",  "Chad",  "Dave"  }   )     func  barber()  {      for  {          c  :=  <-­‐seats          fmt.Println("Barber  shaving",  c)      }   }     func  (c  Customer)  enter()  {      select  {      case  seats  <-­‐  c:      default:          fmt.Println("Customer",  c,  "Leaves")      }   }     func  BarberShop()  {      go  barber()      for  _,  c  :=  range  customers  {          go  c.enter()      }   }  
  • 34. version   build   test   get   install     fmt   …   build  -­‐-­‐race  (1.1+)   GO  COMMAND  
  • 35. h8p://golang.org/   h8p://tour.golang.org/   h8ps://code.google.com/p/go-­‐wiki/wiki/Projects   h8ps://groups.google.com/forum/#!forum/golang-­‐nuts   #go-­‐nuts  on  irc.freenode.net   h8ps://www.facebook.com/groups/golanggonuts