SlideShare a Scribd company logo
1 of 69
Download to read offline
#golang
Pascal C/Asm Perl Java
Evolution of a software developer
PaintGo
A little bit of history…
2007 2009 2012 2013 2015
The beginning
Open sourced
1.0 1.1 1.5
Where used?
https://github.com/golang/go/wiki/GoUsers
Google, Docker, Heroku, Cloud Foundry, CoreOS,
InfluxDB, Dropbox, OpenShift, SoundCloud,
Toggl, etc.
In the clouds!
“Can't reach the pedals. no brakes.
gaining speed. eyes bulging in horror.
technical debt crash eminent. “
— Tim Dysinger, @dysinger
Paul Phillips
@extempore2
“go is a terrible, terrible language, yet
still a major productivity boost.
Amdahl's law in another context.”
“You often see languages which are
fighting the last war. Go is fighting
the War of 1812.”
“reduce: what you will do with your
expectations after you start with Go”
“Rust and Scala drown you in
complexity. Go drowns you in
simplicity.”
Paul Phillips
@extempore2
Tour of Go
tour.golang.org
package  main  
import  "fmt"  
func  main()  {  
   fmt.Println("Hello,  Devclub!")  
}  
package  main  
import  "fmt"  
func  main()  {  
   fmt.Println("Hello,  Devclub!")  
}  
Java-developers reaction to the capital
letter in a function name
Missing stuff
No classes
No generics
No inheritance
No method overriding
No exceptions
etc
No generics? No exceptions? Wut!?
Features
Functions
Structures
Interfaces
Methods
Slices
Pointers
Go-routines
Channels
func  main()  {  
   fmt.Println("1  +  2  =",  add(1,  2))  
}  
func  add(a  int,  b  int)  int  {  
   return  a  +  b  
}
Functions
func  main()  {  
   fmt.Println("1  +  2  =",  add(1,  2))  
}  
func  add(a  int,  b  int)  int  {  
   return  a  +  b  
}
Functions
func  main()  {  
   fmt.Println("1  +  2  =",  add(1,  2))  
}  
func  add(a,  b  int)  int  {  
   return  a  +  b  
}
Functions
func  main()  {  
    s,  p  :=  calculate(1,  2)  
   fmt.Printf("1+2=%d,  1*2=%d",  s,  p)  
}  
func  calculate(a,  b  int)  (int,  int)  {  
    return  a  +  b,  a  *  b  
}
Functions
func  main()  {  
    s,  p  :=  calculate(1,  2)  
   fmt.Printf("1+2=%d,  1*2=%d",  s,  p)  
}  
func  calculate(a,  b  int)  (int,  int)  {  
    return  a  +  b,  a  *  b  
}
Functions
func  main()  {  
    s,  p  :=  calculate(1,  2)  
   fmt.Printf("1+2=%d,  1*2=%d",  s,  p)  
}  
func  calculate(a,  b  int)  (s,  p  int)  {  
    s  :=  a  +  b  
    p  :=  a  *  b  
    return  
}
Functions
func  main()  {  
    double  :=  func(a  int)  int  {    
        return  a  *  2  
    }  
   double(14)  
}  
Functions as values
func  main()  {  
    double  :=  factory()  
   double(14)  
}  
func  factory()  func(a  int)  int  {  
    return  func(a  int)  int  {    
        return  a  *  2  
    }  
}
Functions as values
Arrays
var  a  [4]int  
a[0]  =  1  
i  :=  a[0]
http://blog.golang.org/go-slices-usage-and-internals
arr  :=  [2]string{"Foo",  "Bar"}
arr  :=  […]string{"Foo",  "Bar"}
Slices
a  :=  []int{1,  2,  3}      //  [1  2  3]
No size definition
b  :=  append(a,  4,  5)    //  [1  2  3  4  5]
c  :=  make(c,  3)              //  [0  0  0]
d  :=  b[1:3]                      //  [2  3]
e  :=  b[:3]                        //  [1  2  3]
Maps
   monthdays  :=  map[string]int{  
      "Jan":  31,  "Feb":  28,  "Mar":  31,  
      "Apr":  30,  "May":  31,  "Jun":  30,  
      "Jul":  31,  "Aug":  31,  "Sep":  30,  
      "Oct":  31,  "Nov":  30,  "Dec":  31,  
   }  
   for  month,  days  :=  range  monthdays  {  
      fmt.Println(month,  days)  
   }
Maps
   monthdays  :=  map[string]int{  
      "Jan":  31,  "Feb":  28,  "Mar":  31,  
      "Apr":  30,  "May":  31,  "Jun":  30,  
      "Jul":  31,  "Aug":  31,  "Sep":  30,  
      "Oct":  31,  "Nov":  30,  "Dec":  31,  
   }  
   for  month,  days  :=  range  monthdays  {  
      fmt.Println(month,  days)  
   }
Obligatory comma!?
Maps
   monthdays  :=  map[string]int{  
      "Jan":  31,  "Feb":  28,  "Mar":  31,  
      "Apr":  30,  "May":  31,  "Jun":  30,  
      "Jul":  31,  "Aug":  31,  "Sep":  30,  
      "Oct":  31,  "Nov":  30,  "Dec":  31,  
   }  
   value,  ok  :=  monthdays["Jan"]

    fmt.Println(value)    //    31  
    fmt.Println(ok)          //    true
Pointers
var  p  *int  
i  :=  42  
p  =  &i    
fmt.Println(*p)  
*p  =  21  
fmt.Println(i)
42
21
Pointers
var  p  *int  
i  :=  42  
p  =  &i    
fmt.Println(*p)  
*p  =  21  
fmt.Println(i)
Pointers
var  p  *int  
i  :=  42  
p  =  &i    
fmt.Println(*p)  
*p  =  21  
fmt.Println(i)
No pointer
arithmetics
Structures
type  Vertex  struct  {  
    X  int  
    Y  int  
}  
Structures
type  Vertex  struct  {  
    X  int  
    Y  int  
}  
func  main()  {  
    fmt.Println(Vertex{1,  2})  
}
Methods
type  Vertex  struct  {  
    X  int  
    Y  int  
}  
func  (v  Vertex)  Total()  int  {  
    return  v.X  +  v.Y  
}
Methods
type  Vertex  struct  {  
    X  int  
    Y  int  
}  
func  (v  Vertex)  Total()  int  {  
    return  v.X  +  v.Y  
}
v  :=  Vertex{1,  2}  
v.Total()
Interfaces
type  Entity  interface  {  
    Total()  int  
}  
Interfaces
type  Entity  interface  {  
    Total()  int  
}  
Vertex implements Entity
func  (v  Vertex)  Total()  int  {  
    return  v.X  +  v.Y  
}
Interfaces
v  :=  Vertex  {1,  2}  
blah(v)
func  blah(e  Entity)  {  
      e.Total()  
}
Interfaces
func  foo(x  interface{})  int  {  
      x.(Vertex).Total()  
}
Interfaces
func  foo(x  interface{})  int  {  
      x.(Vertex).Total()  
}
panic:  interface  conversion:  interface  is  main.Vertex2,  not  main.Vertex  
goroutine  1  [running]:  
main.main()  
   main.go:25  +0xcd  
exit  status  2  
foo(Vertex2{1,2})
A programmer had a problem. He
thought to solve it with threads.
two Now problems. he has
Go-routines
foo(Vertex2{1,2})
go  foo(Vertex2{1,2})
Usual function call
Function call in a go-routine
func  ready(w  string,  sec  int)  {  
   time.Sleep(time.Duration(sec)  *  time.Second)  
   fmt.Println(w,  "is  ready!")  
}  
func  main()  {  
   go  ready("Tea",  2)  
   go  ready("Coffee",  1)  
   fmt.Println("I'm  waiting")  
   time.Sleep(5  *  time.Second)  
}
I’m waiting
Coffee is ready
Tea is ready
Channels
ci  :=  make(chan  int)  
cs  :=  make(chan  string)  
cf  :=  make(chan  interface{})
ci <- 1 ← send value 1 into channel ci
i := <-ci ← read int from channel ci
var  c  chan  int  
func  ready(w  string,  sec  int)  {  
   time.Sleep(time.Duration(sec)  *  time.Second)  
   fmt.Println(w,  "is  ready!”)  
    с  <-­‐  1  
}  
func  main()  {  
   go  ready("Tea",  2)  
   go  ready("Coffee",  1)  
   fmt.Println("I'm  waiting")  
    <-­‐c  
    <-­‐c  
}
var  done  =  make(chan  bool)  
var  msgs  =  make(chan  int)  
func  produce()  {  
   for  i  :=  0;  i  <  10;  i++  {  
      msgs  <-­‐  i  
   }  
   done  <-­‐  true  
}  
func  consume()  {  
   for  {  
      msg  :=  <-­‐msgs  
      println(msg)  
   }  
}  
func  main()  {  
   go  produce()  
   go  consume()  
   <-­‐  done  
}
var  done  =  make(chan  bool)  
var  msgs  =  make(chan  int)  
func  produce()  {  
   for  i  :=  0;  i  <  10;  i++  {  
      msgs  <-­‐  i  
   }  
   done  <-­‐  true  
}  
func  consume()  {  
   for  {  
      msg  :=  <-­‐msgs  
      println(msg)  
   }  
}  
func  main()  {  
   go  produce()  
   go  consume()  
   <-­‐  done  
}
Start  go-­‐routines
var  done  =  make(chan  bool)  
var  msgs  =  make(chan  int)  
func  produce()  {  
   for  i  :=  0;  i  <  10;  i++  {  
      msgs  <-­‐  i  
   }  
   done  <-­‐  true  
}  
func  consume()  {  
   for  {  
      msg  :=  <-­‐msgs  
      println(msg)  
   }  
}  
func  main()  {  
   go  produce()  
   go  consume()  
   <-­‐  done  
}
Send  values
var  done  =  make(chan  bool)  
var  msgs  =  make(chan  int)  
func  produce()  {  
   for  i  :=  0;  i  <  10;  i++  {  
      msgs  <-­‐  i  
   }  
   done  <-­‐  true  
}  
func  consume()  {  
   for  {  
      msg  :=  <-­‐msgs  
      println(msg)  
   }  
}  
func  main()  {  
   go  produce()  
   go  consume()  
   <-­‐  done  
}
Receive  values  and  print
var  done  =  make(chan  bool)  
var  msgs  =  make(chan  int)  
func  produce()  {  
   for  i  :=  0;  i  <  10;  i++  {  
      msgs  <-­‐  i  
   }  
   done  <-­‐  true  
}  
func  consume()  {  
   for  {  
      msg  :=  <-­‐msgs  
      println(msg)  
   }  
}  
func  main()  {  
   go  produce()  
   go  consume()  
   <-­‐  done  
}
Done!
Environment
https://golang.org/doc/code.html#Workspaces
Environment
Environment
Tooling
• go (version, build, test, get, install, …)
• gofmt
• godoc
• Editors (vim, atom, IntelliJ IDEA,
Sublime Text)
My choice
What’s missing?
Debugger
IntelliJ IDEA plugin is still in development
Can use GDB, but better do something else instead
Dependency management
A lot of different solutions, no de facto standard
-vendor option in 1.5
Cross-compilation
http://dave.cheney.net/2015/03/03/cross-compilation-just-got-
a-whole-lot-better-in-go-1-5
env GOOS=linux GOARCH=386 go build hello.go
1. Build on Mac for Linux
2. Run the binary without installing
extra dependencies or runtime on Linux host
Testing
package  math  
func  Add(a,  b  int)  int  {  
   return  a  +  b  
} package  math  
import  "testing"  
func  TestAdd(t  *testing.T){  
   if  Add(1,  3)  !=  4  {  
      t.Error("Expecting  4")  
   }  
}  
Testing
package  math  
func  Add(a,  b  int)  int  {  
   return  a  +  b  
} package  math  
import  "testing"  
func  TestAdd(t  *testing.T){  
   if  Add(1,  3)  !=  4  {  
      t.Error("Expecting  4")  
   }  
}  
/usr/local/go/bin/go  test  -­‐v  ./...  -­‐run  ^TestAdd$  
Testing  started  at  03:35  ...  
?         _/Users/anton/work-­‐src/mygo   [no  test  files]PASS  
ok       _/Users/anton/work-­‐src/mygo/math   0.007s
Q: Can you build the enterprise apps in Go?
And now a million $$ question
https://www.youtube.com/watch?v=cFJkLfujOts
Building bank in Go:
A: Apparently, you can :)
Can I haz
decimal type?
https://github.com/shopspring/decimal
import  "github.com/shopspring/decimal"  
…  
x,  _  :=  decimal.NewFromString("0.1")

sum  :=  x.Add(x).Add(x) // 0.3
import  (  
   "net/http"  
   "fmt"  
)  
func  handler(w  http.ResponseWriter,    
                          r  *http.Request)  {  
   fmt.Fprintf(w,  "Welcome!")  
}  
func  main()  {  
   http.HandleFunc("/",  handler)  
   http.ListenAndServe(":8080",  nil)  
}
Compare  to  Java?
Frameworks
Gorilla web toolkit http://www.gorillatoolkit.org/
Go-Kit http://gokit.io
List of various frameworks and libraries:
https://github.com/avelino/awesome-go
Resources
http://www.miek.nl/downloads/Go/Learning-Go-latest.pdf
https://tour.golang.org
http://blog.golang.org
https://www.youtube.com/playlist?
list=PLMW8Xq7bXrG58Qk-9QSy2HRh2WVeIrs7e
https://www.youtube.com/channel/
UCx9QVEApa5BKLw9r8cnOFEA
Gopher Academy:
dotGo:
https://gist.github.com/kachayev/21e7fe149bc5ae0bd878
Channels are not enough:
http://dave.cheney.net/2015/08/08/performance-
without-the-event-loop
Performance without event loop:
@antonarhipov
http://www.slideshare.net/arhan
https://speakerdeck.com/antonarhipov

More Related Content

What's hot

What's hot (20)

Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
 
Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1Cleanup and new optimizations in WPython 1.1
Cleanup and new optimizations in WPython 1.1
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlin
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
 
Rust
RustRust
Rust
 
Go concurrency
Go concurrencyGo concurrency
Go concurrency
 
Don't do this
Don't do thisDon't do this
Don't do this
 
The future of async i/o in Python
The future of async i/o in PythonThe future of async i/o in Python
The future of async i/o in Python
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - Coroutine
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
Go Containers
Go ContainersGo Containers
Go Containers
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 

Viewers also liked

Devclub 01/2017 - (Не)адекватное Java-интервью
Devclub 01/2017 - (Не)адекватное Java-интервьюDevclub 01/2017 - (Не)адекватное Java-интервью
Devclub 01/2017 - (Не)адекватное Java-интервью
Anton Arhipov
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
Anton Arhipov
 
Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012
Anton Arhipov
 
Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)
Alexander Podkhalyuzin
 

Viewers also liked (20)

Joker 2016 - Bytecode 101
Joker 2016 - Bytecode 101Joker 2016 - Bytecode 101
Joker 2016 - Bytecode 101
 
JPoint 2016 - Etudes of DIY Java profiler
JPoint 2016 - Etudes of DIY Java profilerJPoint 2016 - Etudes of DIY Java profiler
JPoint 2016 - Etudes of DIY Java profiler
 
Devclub 01/2017 - (Не)адекватное Java-интервью
Devclub 01/2017 - (Не)адекватное Java-интервьюDevclub 01/2017 - (Не)адекватное Java-интервью
Devclub 01/2017 - (Не)адекватное Java-интервью
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
JPoint 2016 - Bytecode
JPoint 2016 - BytecodeJPoint 2016 - Bytecode
JPoint 2016 - Bytecode
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012Jenkins Evolutions - JEEConf 2012
Jenkins Evolutions - JEEConf 2012
 
Scala lecture #4
Scala lecture #4Scala lecture #4
Scala lecture #4
 
Scala #3
Scala #3Scala #3
Scala #3
 
Scala training
Scala trainingScala training
Scala training
 
Scala #2
Scala #2Scala #2
Scala #2
 
Scala для всех (РИФ 2015)
Scala для всех (РИФ 2015)Scala для всех (РИФ 2015)
Scala для всех (РИФ 2015)
 
Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)Under the hood of scala implicits (Scala eXchange 2014)
Under the hood of scala implicits (Scala eXchange 2014)
 
Scala #4
Scala #4Scala #4
Scala #4
 
Erlang
ErlangErlang
Erlang
 
Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)
 
Scala plugin for IntelliJ IDEA
Scala plugin for IntelliJ IDEAScala plugin for IntelliJ IDEA
Scala plugin for IntelliJ IDEA
 
Scala #5
Scala #5Scala #5
Scala #5
 

Similar to Something about 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...
Mario Fusco
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
Yuren Ju
 

Similar to Something about Golang (20)

Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Hands on lua
Hands on luaHands on lua
Hands on lua
 
About Go
About GoAbout Go
About Go
 
Introduction to Kotlin.pptx
Introduction to Kotlin.pptxIntroduction to Kotlin.pptx
Introduction to Kotlin.pptx
 
01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.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
 
Let's golang
Let's golangLet's golang
Let's golang
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 
The async/await concurrency pattern in Golang
The async/await concurrency pattern in GolangThe async/await concurrency pattern in Golang
The async/await concurrency pattern in Golang
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
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...
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Introduction to go
Introduction to goIntroduction to go
Introduction to go
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 

More from Anton Arhipov

JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdf
Anton Arhipov
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Anton Arhipov
 

More from Anton Arhipov (20)

JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdf
 
Idiomatic kotlin
Idiomatic kotlinIdiomatic kotlin
Idiomatic kotlin
 
TechTrain 2019 - (Не)адекватное техническое интервью
TechTrain 2019 - (Не)адекватное техническое интервьюTechTrain 2019 - (Не)адекватное техническое интервью
TechTrain 2019 - (Не)адекватное техническое интервью
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
Devoxx Ukraine 2018 - Kotlin DSL in under an hourDevoxx Ukraine 2018 - Kotlin DSL in under an hour
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
 
GeeCON Prague 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hourGeeCON Prague 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hour
 
Build pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSLBuild pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSL
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainersJavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
 
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainersGeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
 
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingJavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
 
JavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - TestContainers: integration testing without the hassleJavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - TestContainers: integration testing without the hassle
 
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingJavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
 
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloadingJavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
 
JUG.ua 20170225 - Java bytecode instrumentation
JUG.ua 20170225 - Java bytecode instrumentationJUG.ua 20170225 - Java bytecode instrumentation
JUG.ua 20170225 - Java bytecode instrumentation
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Something about Golang

  • 2. Pascal C/Asm Perl Java Evolution of a software developer PaintGo
  • 3. A little bit of history… 2007 2009 2012 2013 2015 The beginning Open sourced 1.0 1.1 1.5
  • 4. Where used? https://github.com/golang/go/wiki/GoUsers Google, Docker, Heroku, Cloud Foundry, CoreOS, InfluxDB, Dropbox, OpenShift, SoundCloud, Toggl, etc. In the clouds!
  • 5. “Can't reach the pedals. no brakes. gaining speed. eyes bulging in horror. technical debt crash eminent. “ — Tim Dysinger, @dysinger
  • 6. Paul Phillips @extempore2 “go is a terrible, terrible language, yet still a major productivity boost. Amdahl's law in another context.” “You often see languages which are fighting the last war. Go is fighting the War of 1812.”
  • 7. “reduce: what you will do with your expectations after you start with Go” “Rust and Scala drown you in complexity. Go drowns you in simplicity.” Paul Phillips @extempore2
  • 9. package  main   import  "fmt"   func  main()  {     fmt.Println("Hello,  Devclub!")   }  
  • 10. package  main   import  "fmt"   func  main()  {     fmt.Println("Hello,  Devclub!")   }   Java-developers reaction to the capital letter in a function name
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Missing stuff No classes No generics No inheritance No method overriding No exceptions etc
  • 17. No generics? No exceptions? Wut!?
  • 19. func  main()  {     fmt.Println("1  +  2  =",  add(1,  2))   }   func  add(a  int,  b  int)  int  {     return  a  +  b   } Functions
  • 20. func  main()  {     fmt.Println("1  +  2  =",  add(1,  2))   }   func  add(a  int,  b  int)  int  {     return  a  +  b   } Functions
  • 21. func  main()  {     fmt.Println("1  +  2  =",  add(1,  2))   }   func  add(a,  b  int)  int  {     return  a  +  b   } Functions
  • 22. func  main()  {      s,  p  :=  calculate(1,  2)     fmt.Printf("1+2=%d,  1*2=%d",  s,  p)   }   func  calculate(a,  b  int)  (int,  int)  {      return  a  +  b,  a  *  b   } Functions
  • 23. func  main()  {      s,  p  :=  calculate(1,  2)     fmt.Printf("1+2=%d,  1*2=%d",  s,  p)   }   func  calculate(a,  b  int)  (int,  int)  {      return  a  +  b,  a  *  b   } Functions
  • 24. func  main()  {      s,  p  :=  calculate(1,  2)     fmt.Printf("1+2=%d,  1*2=%d",  s,  p)   }   func  calculate(a,  b  int)  (s,  p  int)  {      s  :=  a  +  b      p  :=  a  *  b      return   } Functions
  • 25. func  main()  {      double  :=  func(a  int)  int  {            return  a  *  2      }     double(14)   }   Functions as values
  • 26. func  main()  {      double  :=  factory()     double(14)   }   func  factory()  func(a  int)  int  {      return  func(a  int)  int  {            return  a  *  2      }   } Functions as values
  • 27. Arrays var  a  [4]int   a[0]  =  1   i  :=  a[0] http://blog.golang.org/go-slices-usage-and-internals arr  :=  [2]string{"Foo",  "Bar"} arr  :=  […]string{"Foo",  "Bar"}
  • 28. Slices a  :=  []int{1,  2,  3}      //  [1  2  3] No size definition b  :=  append(a,  4,  5)    //  [1  2  3  4  5] c  :=  make(c,  3)              //  [0  0  0] d  :=  b[1:3]                      //  [2  3] e  :=  b[:3]                        //  [1  2  3]
  • 29. Maps   monthdays  :=  map[string]int{       "Jan":  31,  "Feb":  28,  "Mar":  31,       "Apr":  30,  "May":  31,  "Jun":  30,       "Jul":  31,  "Aug":  31,  "Sep":  30,       "Oct":  31,  "Nov":  30,  "Dec":  31,     }     for  month,  days  :=  range  monthdays  {       fmt.Println(month,  days)     }
  • 30. Maps   monthdays  :=  map[string]int{       "Jan":  31,  "Feb":  28,  "Mar":  31,       "Apr":  30,  "May":  31,  "Jun":  30,       "Jul":  31,  "Aug":  31,  "Sep":  30,       "Oct":  31,  "Nov":  30,  "Dec":  31,     }     for  month,  days  :=  range  monthdays  {       fmt.Println(month,  days)     } Obligatory comma!?
  • 31. Maps   monthdays  :=  map[string]int{       "Jan":  31,  "Feb":  28,  "Mar":  31,       "Apr":  30,  "May":  31,  "Jun":  30,       "Jul":  31,  "Aug":  31,  "Sep":  30,       "Oct":  31,  "Nov":  30,  "Dec":  31,     }     value,  ok  :=  monthdays["Jan"]
    fmt.Println(value)    //    31      fmt.Println(ok)          //    true
  • 32. Pointers var  p  *int   i  :=  42   p  =  &i     fmt.Println(*p)   *p  =  21   fmt.Println(i) 42 21
  • 33. Pointers var  p  *int   i  :=  42   p  =  &i     fmt.Println(*p)   *p  =  21   fmt.Println(i)
  • 34. Pointers var  p  *int   i  :=  42   p  =  &i     fmt.Println(*p)   *p  =  21   fmt.Println(i) No pointer arithmetics
  • 35. Structures type  Vertex  struct  {      X  int      Y  int   }  
  • 36. Structures type  Vertex  struct  {      X  int      Y  int   }   func  main()  {      fmt.Println(Vertex{1,  2})   }
  • 37. Methods type  Vertex  struct  {      X  int      Y  int   }   func  (v  Vertex)  Total()  int  {      return  v.X  +  v.Y   }
  • 38. Methods type  Vertex  struct  {      X  int      Y  int   }   func  (v  Vertex)  Total()  int  {      return  v.X  +  v.Y   } v  :=  Vertex{1,  2}   v.Total()
  • 39. Interfaces type  Entity  interface  {      Total()  int   }  
  • 40. Interfaces type  Entity  interface  {      Total()  int   }   Vertex implements Entity func  (v  Vertex)  Total()  int  {      return  v.X  +  v.Y   }
  • 41. Interfaces v  :=  Vertex  {1,  2}   blah(v) func  blah(e  Entity)  {        e.Total()   }
  • 42. Interfaces func  foo(x  interface{})  int  {        x.(Vertex).Total()   }
  • 43. Interfaces func  foo(x  interface{})  int  {        x.(Vertex).Total()   } panic:  interface  conversion:  interface  is  main.Vertex2,  not  main.Vertex   goroutine  1  [running]:   main.main()     main.go:25  +0xcd   exit  status  2   foo(Vertex2{1,2})
  • 44. A programmer had a problem. He thought to solve it with threads. two Now problems. he has
  • 46. func  ready(w  string,  sec  int)  {     time.Sleep(time.Duration(sec)  *  time.Second)     fmt.Println(w,  "is  ready!")   }   func  main()  {     go  ready("Tea",  2)     go  ready("Coffee",  1)     fmt.Println("I'm  waiting")     time.Sleep(5  *  time.Second)   } I’m waiting Coffee is ready Tea is ready
  • 47. Channels ci  :=  make(chan  int)   cs  :=  make(chan  string)   cf  :=  make(chan  interface{}) ci <- 1 ← send value 1 into channel ci i := <-ci ← read int from channel ci
  • 48. var  c  chan  int   func  ready(w  string,  sec  int)  {     time.Sleep(time.Duration(sec)  *  time.Second)     fmt.Println(w,  "is  ready!”)      с  <-­‐  1   }   func  main()  {     go  ready("Tea",  2)     go  ready("Coffee",  1)     fmt.Println("I'm  waiting")      <-­‐c      <-­‐c   }
  • 49. var  done  =  make(chan  bool)   var  msgs  =  make(chan  int)   func  produce()  {     for  i  :=  0;  i  <  10;  i++  {       msgs  <-­‐  i     }     done  <-­‐  true   }   func  consume()  {     for  {       msg  :=  <-­‐msgs       println(msg)     }   }   func  main()  {     go  produce()     go  consume()     <-­‐  done   }
  • 50. var  done  =  make(chan  bool)   var  msgs  =  make(chan  int)   func  produce()  {     for  i  :=  0;  i  <  10;  i++  {       msgs  <-­‐  i     }     done  <-­‐  true   }   func  consume()  {     for  {       msg  :=  <-­‐msgs       println(msg)     }   }   func  main()  {     go  produce()     go  consume()     <-­‐  done   } Start  go-­‐routines
  • 51. var  done  =  make(chan  bool)   var  msgs  =  make(chan  int)   func  produce()  {     for  i  :=  0;  i  <  10;  i++  {       msgs  <-­‐  i     }     done  <-­‐  true   }   func  consume()  {     for  {       msg  :=  <-­‐msgs       println(msg)     }   }   func  main()  {     go  produce()     go  consume()     <-­‐  done   } Send  values
  • 52. var  done  =  make(chan  bool)   var  msgs  =  make(chan  int)   func  produce()  {     for  i  :=  0;  i  <  10;  i++  {       msgs  <-­‐  i     }     done  <-­‐  true   }   func  consume()  {     for  {       msg  :=  <-­‐msgs       println(msg)     }   }   func  main()  {     go  produce()     go  consume()     <-­‐  done   } Receive  values  and  print
  • 53. var  done  =  make(chan  bool)   var  msgs  =  make(chan  int)   func  produce()  {     for  i  :=  0;  i  <  10;  i++  {       msgs  <-­‐  i     }     done  <-­‐  true   }   func  consume()  {     for  {       msg  :=  <-­‐msgs       println(msg)     }   }   func  main()  {     go  produce()     go  consume()     <-­‐  done   } Done!
  • 54.
  • 58. Tooling • go (version, build, test, get, install, …) • gofmt • godoc • Editors (vim, atom, IntelliJ IDEA, Sublime Text)
  • 60. What’s missing? Debugger IntelliJ IDEA plugin is still in development Can use GDB, but better do something else instead Dependency management A lot of different solutions, no de facto standard -vendor option in 1.5
  • 61. Cross-compilation http://dave.cheney.net/2015/03/03/cross-compilation-just-got- a-whole-lot-better-in-go-1-5 env GOOS=linux GOARCH=386 go build hello.go 1. Build on Mac for Linux 2. Run the binary without installing extra dependencies or runtime on Linux host
  • 62. Testing package  math   func  Add(a,  b  int)  int  {     return  a  +  b   } package  math   import  "testing"   func  TestAdd(t  *testing.T){     if  Add(1,  3)  !=  4  {       t.Error("Expecting  4")     }   }  
  • 63. Testing package  math   func  Add(a,  b  int)  int  {     return  a  +  b   } package  math   import  "testing"   func  TestAdd(t  *testing.T){     if  Add(1,  3)  !=  4  {       t.Error("Expecting  4")     }   }   /usr/local/go/bin/go  test  -­‐v  ./...  -­‐run  ^TestAdd$   Testing  started  at  03:35  ...   ?         _/Users/anton/work-­‐src/mygo   [no  test  files]PASS   ok       _/Users/anton/work-­‐src/mygo/math   0.007s
  • 64. Q: Can you build the enterprise apps in Go? And now a million $$ question https://www.youtube.com/watch?v=cFJkLfujOts Building bank in Go: A: Apparently, you can :)
  • 65. Can I haz decimal type? https://github.com/shopspring/decimal import  "github.com/shopspring/decimal"   …   x,  _  :=  decimal.NewFromString("0.1")
 sum  :=  x.Add(x).Add(x) // 0.3
  • 66. import  (     "net/http"     "fmt"   )   func  handler(w  http.ResponseWriter,                              r  *http.Request)  {     fmt.Fprintf(w,  "Welcome!")   }   func  main()  {     http.HandleFunc("/",  handler)     http.ListenAndServe(":8080",  nil)   } Compare  to  Java?
  • 67. Frameworks Gorilla web toolkit http://www.gorillatoolkit.org/ Go-Kit http://gokit.io List of various frameworks and libraries: https://github.com/avelino/awesome-go