SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
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	
  

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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...
 

Último

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

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