SlideShare una empresa de Scribd logo
1 de 137
Descargar para leer sin conexión
Why Ruby Must Go!
Why must Ruby go?
Why must Ruby go?
Why Ruby Must Go! 
What can Ruby incorporate from Go? 
What is Programmer Awareness? 
As a Rubyist, what does Go teach me?
@gautamrege 
@joshsoftware 
! 
@rubyconfindia
Programming Paradigms 
Imperative 
Declarative 
Procedural 
Functional 
Object Oriented 
Symbolic
Programming Paradigms 
Imperative 
Declarative 
Procedural 
Functional 
Object Oriented 
Symbolic 
C++! 
Java! 
Python! 
Ruby 
Order of execution / steps One or more subroutines
Programming Paradigms 
Imperative 
Declarative 
Procedural 
Order of execution / steps One or more subroutines 
Functional 
Object Oriented 
Symbolic 
Pascal! 
FORTRAN! 
C
Programming Paradigms 
Imperative 
Declarative 
Procedural 
Order of execution / steps One or more subroutines 
Functional 
Object Oriented 
Symbolic 
Pascal! 
FORTRAN! 
C! 
Go
Go Lang 
C on Steroids
Go Lang C on Steroids
Go Lang C on Steroids 
• No more memory leaks. (Garbage collection)
Go Lang C on Steroids 
• No more memory leaks. (Garbage collection) 
• No more pointer de-referencing. (-> or . )
Go Lang C on Steroids 
• No more memory leaks. (Garbage collection) 
• No more pointer de-referencing. (-> or . ) 
• Support for maps, slices and channels.
Go Lang C on Steroids 
• No more memory leaks. (Garbage collection) 
• No more pointer de-referencing. (-> or . ) 
• Support for maps, slices and channels. 
• Support for closures.
Go Lang C on Steroids 
• No more memory leaks. (Garbage collection) 
• No more pointer de-referencing. (-> or . ) 
• Support for maps, slices and channels. 
• Support for closures. 
• Concurrency: closures, channels & go-routines.
Go is different !
Go is different !
Go is different ! 
• No exceptions, only errors.
Go is different ! 
• No exceptions, only errors. 
• Return multiple values from functions
Go is different ! 
• No exceptions, only errors. 
• Return multiple values from functions 
• Interfaces but no classes (only structs)
Go is different ! 
• No exceptions, only errors. 
• Return multiple values from functions 
• Interfaces but no classes (only structs) 
• No inheritance but embedded structs
Let’s get Going 
And learn Go along the way!
Duck Typing in Ruby
Duck Typing in Ruby 
Programming convenience.! 
Implicit Type Conversions.! 
No complex Type Inference
Duck Typing in Ruby 
Programming convenience.! 
Implicit Type Conversions.! 
No complex Type Inference 
Don’t fight the Type System
Duck Typing in Ruby 
Programming convenience.! 
Implicit Type Conversions.! 
No complex Type Inference 
Don’t fight the Type System 
Code First - Resolve Issues Later
Problems with Duck Typing
Problems with Duck Typing 
No Early Warning System! 
Reactive programming! 
Compiler Time checks!
Problems with Duck Typing 
No Early Warning System! 
Reactive programming! 
Compiler Time checks! 
Type Inference
Problems with Duck Typing 
No Early Warning System! 
Reactive programming! 
Compiler Time checks! 
Type Inference 
Code Once Correctly
Types? Who cares? 
We’re ! 
Rubyists!
Types? Who cares? 
We’re ! 
Rubyists!
Type Checks in Ruby! 
def convert_hashes_to_parameters(key, value, assign_if_converted=true)! 
converted = convert_value_to_parameters(value)! 
#...! 
end! 
! 
def convert_value_to_parameters(value)! 
if value.is_a?(Array) && !converted_arrays.member?(value)! 
#...! 
converted_arrays << converted! 
converted! 
elsif value.is_a?(Parameters) || !value.is_a?(Hash)! 
#...! 
end! 
end
Type Checks in Ruby! 
def convert_hashes_to_parameters(key, value, assign_if_converted=true)! 
converted = convert_value_to_parameters(value)! 
#...! 
end! 
! 
def convert_value_to_parameters(value)! 
if value.is_a?(Array) && !converted_arrays.member?(value)! 
#...! 
converted_arrays << converted! 
converted! 
elsif value.is_a?(Parameters) || !value.is_a?(Hash)! 
#...! 
end! 
end
Type Checks in Ruby! 
def convert_hashes_to_parameters(key, value, assign_if_converted=true)! 
converted = convert_value_to_parameters(value)! 
#...! 
end! 
! 
def convert_value_to_parameters(value)! 
if value.is_a?(Array) && !converted_arrays.member?(value)! 
#...! 
converted_arrays << converted! 
converted! 
elsif value.is_a?(Parameters) || !value.is_a?(Hash)! 
#...! 
end! 
end 
def permit!! 
each_pair do |key, value|! 
value = convert_hashes_to_parameters(key, value)! 
#...! 
end
Type Checks in Ruby! 
def convert_hashes_to_parameters(key, value, assign_if_converted=true)! 
converted = convert_value_to_parameters(value)! 
#...! 
end! 
! 
def convert_value_to_parameters(value)! 
if value.is_a?(Array) && !converted_arrays.member?(value)! 
#...! 
converted_arrays << converted! 
converted! 
elsif value.is_a?(Parameters) || !value.is_a?(Hash)! 
#...! 
end! 
end 
def permit!! 
each_pair do |key, value|! 
value = convert_hashes_to_parameters(key, value)! 
#...! 
end 
Strong Parameters!
To Duck or to Type
To Duck or to Type 
Best of Both worlds
To Duck or to Type 
Light weight 1-level Type check
To Duck or to Type 
Light weight 1-level Type check 
type point int 
! 
func main() { 
var i int = 2 
var j point = 2 
! 
i == j 
}
To Duck or to Type 
Light weight 1-level Type check 
type point int 
! 
func main() { 
var i int = 2 
var j point = 2 
Variable name first, then the type 
! 
i == j 
}
To Duck or to Type 
Light weight 1-level Type check 
type point int 
! 
func main() { 
var i int = 2 
var j point = 2 
! 
i == j 
}
To Duck or to Type 
Light weight 1-level Type check 
type point int 
! 
func main() { 
var i int = 2 
var j point = 2 
! 
i == j 
} 
Error: invalid operation: i == j 
(mismatched types int and point)
Ruby re-defines Object 
Oriented Concepts, 
Go re-defines 
programming itself! 
“ 
”
Programmer Awareness
Programmer Awareness 
%QORKNGT
Programmer Awareness 
%QORKNGT 
4GXKGYGT
Programmer Awareness 
%QORKNGT 
4GXKGYGT 
(TCOGYQTM
Programmer Awareness 
%QORKNGT 
4GXKGYGT 
(TCOGYQTM 
.CPIWCIG
Programmer Awareness 
Variable declaration and assignment
Programmer Awareness 
Variable declaration and assignment 
y 
y
Programmer Awareness 
Variable declaration and assignment 
y := 2 // y is of type int! 
y = "3" 
Implicit declaration
Programmer Awareness 
Variable declaration and assignment 
y := 2 // y is of type int! 
y = "3" 
Assignment
Programmer Awareness 
Variable declaration and assignment 
y := 2 // y is of type int! 
y = "3" 
COMPLIER ERROR! 
cannot use “3” (type string) as type int in 
assignment
Programmer ERROR? 
Variable declaration and assignment 
y := 2 // y is of type int! 
y = "3" 
As a programmer, we probably re-assigned 
“y” to a String by mistake!
Programmer AWARENESS 
Variable declaration and assignment 
y := 2 // y is of type int! 
y, _ = strconv.Atoi("3") 
There’s always a right way to do things!
! 
Eh… what?
! 
Eh… what? 
https://flic.kr/p/mnZgQw
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! d, err := f.Stat()! 
}
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! d, err := f.Stat()! 
} 
import packages
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! d, err := f.Stat()! 
} 
Exported function
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! d, err := f.Stat()! 
}
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! d, err := f.Stat()! 
} 
I’m practical. You 
can re-declare err in your 
code!* 
* Conditions apply
Programmer Awareness 
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! d, err := f.Stat()! 
}
Programmer Awareness 
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! f, err := f.Stat()! 
}
Programmer Awareness 
Variable Re-declaration 
import "os"! 
Error: no new 
! 
variables on left 
func main() {! 
side of := 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! f, err := f.Stat()! 
} Hmm.. I think you re-used 
the variable f by 
mistake!
Programmer Awareness 
Variable Re-declaration 
import "os"! 
! 
func main() {! 
! f, err := os.Open("somefile")! 
! // handle error! 
! 
! f, err = f.Open("other file")! 
} 
Re-assign ! 
explicitly.. 
With Great Power Comes 
Great Responsibility
https://flic.kr/p/kSSWb
Overloading 
but first …
Lets Go a little more! 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Dimensions)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
Type Declaration
Lets Go a little more! 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Dimensions)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
Exported Array
Lets Go a little more! 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Dimensions)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
Exported Array 
The size in Array is part of the type! 
[2]float32 != [3]float32
Lets Go a little more! 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Dimensions)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
Embedding! 
(Not inheritance)
Lets Go a little more! 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Dimensions)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
hotel.Dimensions and not 
hotel.Hall.Dimensions
Lets Go a little more! 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Name)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
Dimensions)!
Lets Go a little more! 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Name)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
}
Programmer Awareness 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Name)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
}
Programmer Awareness 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Name)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
} 
Which Name should 
I use? 
Error: Ambiguous 
selector hotel.Name!
Programmer Awareness 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Name)Hall.! 
Name)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
}
Programmer Awareness 
type Layout struct {! 
! Name string! 
Capacity int! 
}! 
! 
type Hall struct {! 
! Name string! 
! Dimensions [2]float32! 
}! 
! 
type Hotel struct {! 
! Location string! 
! Hall! 
! Layout! 
} 
func main() {! 
! hotel := Hotel{}! 
! fmt.Println(hotel.Hall.Name)! 
! 
! h := make(map[string]Hotel)! 
! 
! for name, _ := range h {! 
! ! fmt.Println(name)! 
! }! 
}
Modules in Ruby 
module Layout! 
def manager! 
p "Layout Manager"! 
end! 
end! 
! 
module Hall! 
def manager! 
p "Hall Manager"! 
end! 
end! 
! 
class Hotel! 
include Layout! 
include Hall! 
end 
def main! 
hotel = Hotel.new! 
p hotel.manager! 
end
Modules in Ruby 
module Layout! 
def manager! 
p "Layout Manager"! 
end! 
end! 
! 
module Hall! 
def manager! 
p "Hall Manager"! 
end! 
end! 
! 
class Hotel! 
include Layout! 
include Hall! 
end 
def main! 
hotel = Hotel.new! 
p hotel.manager! 
end 
Which language is 
this dude?
Include modules 
in order! 
https://flic.kr/p/e7SnAa
Programmer Awareness 
Iterating a Hash 
hotels := make(map[string]Hotel)! 
! 
for name, _ := range hotels {! 
! fmt.Println(name)! 
}
Programmer Awareness 
Iterating a Hash 
hotels := make(map[string]Hotel)! 
! 
for name, _ := range hotels {! 
! fmt.Println(name)! 
} 
Map of strings and Hotels
Programmer Awareness 
Iterating a Hash 
hotels := make(map[string]Hotel)! 
! 
for name, _ := range hotels {! 
! fmt.Println(name)! 
} 
Easy iteration syntax!
Programmer Awareness 
Iterating a Hash 
hotels := make(map[string]Hotel)! 
! 
for name, _ := range hotels {! 
! fmt.Println(name)! 
} Blank Identifier - ignore value
Programmer Awareness 
Iterating a Hash 
hotels := make(map[string]Hotel)! 
! 
for name, _ := range hotels {! 
! fmt.Println(name)! 
}
Programmer Awareness 
Iterating a Hash 
hotels := make(map[string]Hotel)! 
! 
for name, _ := range hotels {! 
! fmt.Println(name)! 
} 
Bad practice! ! 
I’ll randomise the 
order!
Ordered Hashes!
Ordered Hashes!
Pushing some 
Goodies into Ruby 
https://flic.kr/p/awu6ZA
Defer 
mu sync.Mutex! 
! 
func foo() {! 
mu.Lock()! 
defer mu.unLock()! 
// do something...! 
} 
https://flic.kr/p/awu6ZA
Defer 
func trace(s string) { fmt.Println("entering:", s) }! 
func untrace(s string) { fmt.Println("leaving:", s) }! 
! 
func a() {! 
trace("a")! 
defer untrace("a")! 
// do something....! 
} 
https://flic.kr/p/awu6ZA
Concurrency 
Parallelism 
Multi-core Processing 
https://flic.kr/p/awu6ZA
Example - Relay Race 
• 4 legs of the race 
• Each leg does processing concurrently. 
• Completion should be in order. (pass the baton)
Concurrent Example 
Leg 1 
Leg 2 
Leg 3 
Leg 4
Concurrent Processing 
Leg 
1 
Leg 
2 
Leg 
3 Leg 
4 
CPU churn - CPU time 
consuming operation.
Completion Order 
Leg 1 
Leg 2 
Leg 3 
Leg 4
Completion Order 
Leg 1 
Leg 2 
Leg 3 
Leg 4
Completion Order 
Leg 1 
Leg 2 
Leg 3 
Leg 4
Completion Order 
Leg 1 
Leg 2 
Leg 3 
Leg 4
CSP! 
Communicating Sequential 
Processes 
https://flic.kr/p/6MwYFo https://flic.kr/p/awu6ZA
CSP! 
Communicating Sequential 
Processes 
since 1978 !! 
https://flic.kr/p/awu6ZA 
https://flic.kr/p/6MwYFo
package main 
! 
import ( 
"fmt" 
"runtime" 
"sync" 
) 
! 
var wg sync.WaitGroup 
! 
/* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func main() { 
runtime.GOMAXPROCS(4) 
! 
baton := make(chan int) 
wg.Add(4) 
! 
for i := 1; i < 5; i++ {! 
go run(i, baton)! 
}! 
! 
! ! ! // start the race! 
baton <- 1! 
! 
// wait for relay to finish! 
wg.Wait()! 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func main() { 
runtime.GOMAXPROCS(4) 
! 
baton := make(chan int) 
wg.Add(4) 
! 
for i := 1; i < 5; i++ {! 
go run(i, baton)! 
}! 
! 
! ! ! // start the race! 
baton <- 1! 
! 
// wait for relay to finish! 
wg.Wait()! 
} 
A channel that accepts an int
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func main() { 
runtime.GOMAXPROCS(4) 
! 
baton := make(chan int) 
wg.Add(4) 
! 
for i := 1; i < 5; i++ {! 
go run(i, baton)! 
}! 
! 
! ! ! // start the race! 
baton <- 1! 
! 
// wait for relay to finish! 
wg.Wait()! 
} 
Go Routine
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func main() { 
runtime.GOMAXPROCS(4) 
! 
baton := make(chan int) 
wg.Add(4) 
! 
for i := 1; i < 5; i++ {! 
go run(i, baton)! 
}! 
! 
! ! ! // start the race! 
baton <- 1! 
! 
// wait for relay to finish! 
wg.Wait()! 
} 
Writing to a channel
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func main() { 
runtime.GOMAXPROCS(4) 
! 
baton := make(chan int) 
wg.Add(4) 
! 
for i := 1; i < 5; i++ {! 
go run(i, baton)! 
}! 
! 
! ! ! // start the race! 
baton <- 1! 
! 
// wait for relay to finish! 
wg.Wait()! 
} 
A WaitGroup - wait 
for 4 events!
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func run(leg int, baton chan int) { 
defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) 
! 
! ! // Massive CPU churn! 
! ! for count := 0; count < 300; count++ {! 
! ! ! for char := 0; char < 30000; char++ {! ! ! ! fmt.Printf("")! 
! ! ! }! 
! ! }! 
fmt.Printf("Leg %d.. churned, waiting to ! 
! ! check_baton(leg, baton)! 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func run(leg int, baton chan int) { 
defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) 
Done for WaitGroup 
! 
! ! // Massive CPU churn! 
! ! for count := 0; count < 300; count++ {! 
! ! ! for char := 0; char < 30000; char++ {! ! ! ! fmt.Printf("")! 
! ! ! }! 
! ! }! 
fmt.Printf("Leg %d.. churned, waiting to ! 
! ! check_baton(leg, baton)! 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func check_baton(leg int, baton chan int) {! 
! ! for value := range baton {! 
! ! ! switch value {! 
! ! ! ! case leg:! 
! ! ! ! ! // pass the baton! 
! ! ! ! ! fmt.Println("Finished leg ", leg)! 
! ! ! ! ! if leg == 4 {! 
! ! ! ! ! ! close(baton)! 
! ! ! ! ! } else {! 
! ! ! ! ! ! ! baton <- leg + 1! 
! ! ! ! ! }! 
! ! ! ! ! return! 
! ! ! ! default:! 
! ! ! ! ! // ignore! 
! ! ! ! ! baton <- value! 
! ! ! }! 
! ! }! 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func check_baton(leg int, baton chan int) {! 
! ! for value := range baton {! 
! ! ! switch value {! 
! ! ! ! case leg:Read ! 
or block on a 
! ! ! ! ! // pass the channel 
baton! 
! ! ! ! ! fmt.Println("Finished leg ", leg)! 
! ! ! ! ! if leg == 4 {! 
! ! ! ! ! ! close(baton)! 
! ! ! ! ! } else {! 
! ! ! ! ! ! ! baton <- leg + 1! 
! ! ! ! ! }! 
! ! ! ! ! return! 
! ! ! ! default:! 
! ! ! ! ! // ignore! 
! ! ! ! ! baton <- value! 
! ! ! }! 
! ! }! 
}
Channels in action 
p!ackage main import ( 
"fmt" 
"runtime" 
"sync" 
)! v!ar wg sync.WaitGroup /* 
* Each go-routine sleeps at random(1-5) seconds. 
* This is simulating long working process 
* Then we finish in order 
*/ 
func check_baton(leg int, baton chan int) { 
for value := range baton { 
switch value { 
case leg: 
// pass the baton 
fmt.Println("Finished leg ", leg) 
if leg == 4 { 
close(baton) 
} else { 
baton <- leg + 1 
} 
return 
default: 
// ignore 
baton <- value 
} 
} 
}! func run(leg int, baton chan int) { 
! defer wg.Done() 
fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn 
for count := 0; count < 300; count++ { 
for char := 0; char < 30000; char++ { 
fmt.Printf("") 
} 
! } 
fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) 
}! func main() { 
runtime.GOMAXPROCS(4) ! baton := make(chan int) 
wg.Add(4) for i := 1; i < 5; i++ { 
! go run(i, baton) 
} ! // start the race 
baton <- 1 // wait for relay to finish 
wg.Wait() 
} 
func check_baton(leg int, baton chan int) {! 
! ! for value := range baton {! 
! ! ! switch value {! 
! ! ! ! case leg:! 
! ! ! ! ! // pass the baton! 
! ! ! ! ! fmt.Println("Finished leg ", leg)! 
! ! ! ! ! if leg == 4 {! 
! ! ! ! ! ! close(baton)! 
! ! ! ! ! } else {! 
! ! ! ! ! ! ! baton <- leg + 1! 
! ! ! ! ! }! 
! ! ! ! ! return! 
! ! ! ! default:! 
! ! ! ! ! // ignore! 
! ! ! ! ! baton <- value! 
! ! ! }! 
! ! }! 
}
The Big Fight 
https://flic.kr/p/9AeqD2
Generics? 
Convenient 
Too early still. 
interface{} 
https://flic.kr/p/9AeqD2
Keywords! 
Nah.. no rules, 
https://flic.kr/p/9AeqD2 
rules! 
You need’em 
bro
GIL 
https://flic.kr/p/9AeqD2 
 
Compiled 
language 
FTW
Extending & Embedding 
https://flic.kr/p/9AeqD2 
Yeah 
Nope. ! 
Only Cgo
Tooling 
https://flic.kr/p/9AeqD2 
gem 
bundler 
go tools
Emergency Instructions ! 
OR ! 
Lecture In Aerodynamics
Emergency Instructions
Emergency Instructions
Traction Control! 
Fuel Efficiency! 
Aerodynamics! 
Tyre Temperature
Traction Control! 
Fuel Efficiency! 
Aerodynamics! 
Tyre Temperature
“ Ruby is for developers 
Go is for programmers 
” 
@gautamrege 
@joshsoftware

Más contenido relacionado

La actualidad más candente

Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageSmartLogic
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介Wen-Tien Chang
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer. Haim Michael
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKAdolfo Sanz De Diego
 
Anacronia on speed
Anacronia on speedAnacronia on speed
Anacronia on speedmfontani
 
Rails for PHP Developers
Rails for PHP DevelopersRails for PHP Developers
Rails for PHP DevelopersRobert Dempsey
 
CGI With Object Oriented Perl
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented PerlBunty Ray
 
CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2johnnygoodman
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009scweng
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 

La actualidad más candente (20)

Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Vim week
Vim weekVim week
Vim week
 
Cleancode
CleancodeCleancode
Cleancode
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
 
Designing Ruby APIs
Designing Ruby APIsDesigning Ruby APIs
Designing Ruby APIs
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
 
Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
Anacronia on speed
Anacronia on speedAnacronia on speed
Anacronia on speed
 
Rails for PHP Developers
Rails for PHP DevelopersRails for PHP Developers
Rails for PHP Developers
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
CGI With Object Oriented Perl
CGI With Object Oriented PerlCGI With Object Oriented Perl
CGI With Object Oriented Perl
 
CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 

Similar a RubyConf Portugal 2014 - Why ruby must go!

Moving to modules
Moving to modulesMoving to modules
Moving to modulesSean Mize
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with MoopsMike Friedman
 
Desert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming languageDesert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming languageJames Montemagno
 
Building Interpreters with PyPy
Building Interpreters with PyPyBuilding Interpreters with PyPy
Building Interpreters with PyPyDaniel Neuhäuser
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
"Writing Maintainable JavaScript". Jon Bretman, Badoo
"Writing Maintainable JavaScript". Jon Bretman, Badoo"Writing Maintainable JavaScript". Jon Bretman, Badoo
"Writing Maintainable JavaScript". Jon Bretman, BadooYandex
 
Javascript patterns
Javascript patternsJavascript patterns
Javascript patternsChandan Jog
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsLeonardo Borges
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the RubyistMark
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional ProgrammingJordan Parmer
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtextmeysholdt
 
Go language presentation
Go language presentationGo language presentation
Go language presentationparamisoft
 

Similar a RubyConf Portugal 2014 - Why ruby must go! (20)

Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
Moving to modules
Moving to modulesMoving to modules
Moving to modules
 
Perfect Code
Perfect CodePerfect Code
Perfect Code
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with Moops
 
Desert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming languageDesert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming language
 
Building Interpreters with PyPy
Building Interpreters with PyPyBuilding Interpreters with PyPy
Building Interpreters with PyPy
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Refactoring
RefactoringRefactoring
Refactoring
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
"Writing Maintainable JavaScript". Jon Bretman, Badoo
"Writing Maintainable JavaScript". Jon Bretman, Badoo"Writing Maintainable JavaScript". Jon Bretman, Badoo
"Writing Maintainable JavaScript". Jon Bretman, Badoo
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Javascript patterns
Javascript patternsJavascript patterns
Javascript patterns
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
 
Go(lang) for the Rubyist
Go(lang) for the RubyistGo(lang) for the Rubyist
Go(lang) for the Rubyist
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 
Coscup
CoscupCoscup
Coscup
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
 

Más de Gautam Rege

RubyConf India 2019 - Confessions of a rubypreneur
RubyConf India 2019 - Confessions of a rubypreneurRubyConf India 2019 - Confessions of a rubypreneur
RubyConf India 2019 - Confessions of a rubypreneurGautam Rege
 
GoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGautam Rege
 
Agile india 2017 - Rewarding OpenSource with $$$
Agile india 2017 - Rewarding OpenSource with $$$Agile india 2017 - Rewarding OpenSource with $$$
Agile india 2017 - Rewarding OpenSource with $$$Gautam Rege
 
WIDS - Gamifying Open Source
WIDS - Gamifying Open SourceWIDS - Gamifying Open Source
WIDS - Gamifying Open SourceGautam Rege
 
Gamifying Open Source
Gamifying Open SourceGamifying Open Source
Gamifying Open SourceGautam Rege
 
Affordable Smart Housing - The new revolution
Affordable Smart Housing - The new revolutionAffordable Smart Housing - The new revolution
Affordable Smart Housing - The new revolutionGautam Rege
 
WebSummit 2015 - Gopher it
WebSummit 2015 - Gopher itWebSummit 2015 - Gopher it
WebSummit 2015 - Gopher itGautam Rege
 
Dont test your code
Dont test your codeDont test your code
Dont test your codeGautam Rege
 
Art of speaking at tech conferences
Art of speaking at tech conferencesArt of speaking at tech conferences
Art of speaking at tech conferencesGautam Rege
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Gautam Rege
 
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby Gautam Rege
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyGautam Rege
 
GCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of RubyGCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of RubyGautam Rege
 
Rails Vs CakePHP
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHPGautam Rege
 

Más de Gautam Rege (15)

RubyConf India 2019 - Confessions of a rubypreneur
RubyConf India 2019 - Confessions of a rubypreneurRubyConf India 2019 - Confessions of a rubypreneur
RubyConf India 2019 - Confessions of a rubypreneur
 
GoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPH
 
Agile india 2017 - Rewarding OpenSource with $$$
Agile india 2017 - Rewarding OpenSource with $$$Agile india 2017 - Rewarding OpenSource with $$$
Agile india 2017 - Rewarding OpenSource with $$$
 
WIDS - Gamifying Open Source
WIDS - Gamifying Open SourceWIDS - Gamifying Open Source
WIDS - Gamifying Open Source
 
Gamifying Open Source
Gamifying Open SourceGamifying Open Source
Gamifying Open Source
 
Affordable Smart Housing - The new revolution
Affordable Smart Housing - The new revolutionAffordable Smart Housing - The new revolution
Affordable Smart Housing - The new revolution
 
WebSummit 2015 - Gopher it
WebSummit 2015 - Gopher itWebSummit 2015 - Gopher it
WebSummit 2015 - Gopher it
 
Dont test your code
Dont test your codeDont test your code
Dont test your code
 
Art of speaking at tech conferences
Art of speaking at tech conferencesArt of speaking at tech conferences
Art of speaking at tech conferences
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)
 
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of ruby
 
GCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of RubyGCRC 2014 - The Dark Side of Ruby
GCRC 2014 - The Dark Side of Ruby
 
Rails Vs CakePHP
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHP
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 

Último

Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 

Último (20)

Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 

RubyConf Portugal 2014 - Why ruby must go!

  • 4. Why Ruby Must Go! What can Ruby incorporate from Go? What is Programmer Awareness? As a Rubyist, what does Go teach me?
  • 6. Programming Paradigms Imperative Declarative Procedural Functional Object Oriented Symbolic
  • 7. Programming Paradigms Imperative Declarative Procedural Functional Object Oriented Symbolic C++! Java! Python! Ruby Order of execution / steps One or more subroutines
  • 8. Programming Paradigms Imperative Declarative Procedural Order of execution / steps One or more subroutines Functional Object Oriented Symbolic Pascal! FORTRAN! C
  • 9. Programming Paradigms Imperative Declarative Procedural Order of execution / steps One or more subroutines Functional Object Oriented Symbolic Pascal! FORTRAN! C! Go
  • 10. Go Lang C on Steroids
  • 11. Go Lang C on Steroids
  • 12. Go Lang C on Steroids • No more memory leaks. (Garbage collection)
  • 13. Go Lang C on Steroids • No more memory leaks. (Garbage collection) • No more pointer de-referencing. (-> or . )
  • 14. Go Lang C on Steroids • No more memory leaks. (Garbage collection) • No more pointer de-referencing. (-> or . ) • Support for maps, slices and channels.
  • 15. Go Lang C on Steroids • No more memory leaks. (Garbage collection) • No more pointer de-referencing. (-> or . ) • Support for maps, slices and channels. • Support for closures.
  • 16. Go Lang C on Steroids • No more memory leaks. (Garbage collection) • No more pointer de-referencing. (-> or . ) • Support for maps, slices and channels. • Support for closures. • Concurrency: closures, channels & go-routines.
  • 19. Go is different ! • No exceptions, only errors.
  • 20. Go is different ! • No exceptions, only errors. • Return multiple values from functions
  • 21. Go is different ! • No exceptions, only errors. • Return multiple values from functions • Interfaces but no classes (only structs)
  • 22. Go is different ! • No exceptions, only errors. • Return multiple values from functions • Interfaces but no classes (only structs) • No inheritance but embedded structs
  • 23. Let’s get Going And learn Go along the way!
  • 25. Duck Typing in Ruby Programming convenience.! Implicit Type Conversions.! No complex Type Inference
  • 26. Duck Typing in Ruby Programming convenience.! Implicit Type Conversions.! No complex Type Inference Don’t fight the Type System
  • 27. Duck Typing in Ruby Programming convenience.! Implicit Type Conversions.! No complex Type Inference Don’t fight the Type System Code First - Resolve Issues Later
  • 29. Problems with Duck Typing No Early Warning System! Reactive programming! Compiler Time checks!
  • 30. Problems with Duck Typing No Early Warning System! Reactive programming! Compiler Time checks! Type Inference
  • 31. Problems with Duck Typing No Early Warning System! Reactive programming! Compiler Time checks! Type Inference Code Once Correctly
  • 32. Types? Who cares? We’re ! Rubyists!
  • 33. Types? Who cares? We’re ! Rubyists!
  • 34. Type Checks in Ruby! def convert_hashes_to_parameters(key, value, assign_if_converted=true)! converted = convert_value_to_parameters(value)! #...! end! ! def convert_value_to_parameters(value)! if value.is_a?(Array) && !converted_arrays.member?(value)! #...! converted_arrays << converted! converted! elsif value.is_a?(Parameters) || !value.is_a?(Hash)! #...! end! end
  • 35. Type Checks in Ruby! def convert_hashes_to_parameters(key, value, assign_if_converted=true)! converted = convert_value_to_parameters(value)! #...! end! ! def convert_value_to_parameters(value)! if value.is_a?(Array) && !converted_arrays.member?(value)! #...! converted_arrays << converted! converted! elsif value.is_a?(Parameters) || !value.is_a?(Hash)! #...! end! end
  • 36. Type Checks in Ruby! def convert_hashes_to_parameters(key, value, assign_if_converted=true)! converted = convert_value_to_parameters(value)! #...! end! ! def convert_value_to_parameters(value)! if value.is_a?(Array) && !converted_arrays.member?(value)! #...! converted_arrays << converted! converted! elsif value.is_a?(Parameters) || !value.is_a?(Hash)! #...! end! end def permit!! each_pair do |key, value|! value = convert_hashes_to_parameters(key, value)! #...! end
  • 37. Type Checks in Ruby! def convert_hashes_to_parameters(key, value, assign_if_converted=true)! converted = convert_value_to_parameters(value)! #...! end! ! def convert_value_to_parameters(value)! if value.is_a?(Array) && !converted_arrays.member?(value)! #...! converted_arrays << converted! converted! elsif value.is_a?(Parameters) || !value.is_a?(Hash)! #...! end! end def permit!! each_pair do |key, value|! value = convert_hashes_to_parameters(key, value)! #...! end Strong Parameters!
  • 38. To Duck or to Type
  • 39. To Duck or to Type Best of Both worlds
  • 40. To Duck or to Type Light weight 1-level Type check
  • 41. To Duck or to Type Light weight 1-level Type check type point int ! func main() { var i int = 2 var j point = 2 ! i == j }
  • 42. To Duck or to Type Light weight 1-level Type check type point int ! func main() { var i int = 2 var j point = 2 Variable name first, then the type ! i == j }
  • 43. To Duck or to Type Light weight 1-level Type check type point int ! func main() { var i int = 2 var j point = 2 ! i == j }
  • 44. To Duck or to Type Light weight 1-level Type check type point int ! func main() { var i int = 2 var j point = 2 ! i == j } Error: invalid operation: i == j (mismatched types int and point)
  • 45. Ruby re-defines Object Oriented Concepts, Go re-defines programming itself! “ ”
  • 49. Programmer Awareness %QORKNGT 4GXKGYGT (TCOGYQTM
  • 50. Programmer Awareness %QORKNGT 4GXKGYGT (TCOGYQTM .CPIWCIG
  • 51. Programmer Awareness Variable declaration and assignment
  • 52. Programmer Awareness Variable declaration and assignment y y
  • 53. Programmer Awareness Variable declaration and assignment y := 2 // y is of type int! y = "3" Implicit declaration
  • 54. Programmer Awareness Variable declaration and assignment y := 2 // y is of type int! y = "3" Assignment
  • 55. Programmer Awareness Variable declaration and assignment y := 2 // y is of type int! y = "3" COMPLIER ERROR! cannot use “3” (type string) as type int in assignment
  • 56. Programmer ERROR? Variable declaration and assignment y := 2 // y is of type int! y = "3" As a programmer, we probably re-assigned “y” to a String by mistake!
  • 57. Programmer AWARENESS Variable declaration and assignment y := 2 // y is of type int! y, _ = strconv.Atoi("3") There’s always a right way to do things!
  • 59. ! Eh… what? https://flic.kr/p/mnZgQw
  • 60. Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! d, err := f.Stat()! }
  • 61. Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! d, err := f.Stat()! } import packages
  • 62. Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! d, err := f.Stat()! } Exported function
  • 63. Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! d, err := f.Stat()! }
  • 64. Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! d, err := f.Stat()! } I’m practical. You can re-declare err in your code!* * Conditions apply
  • 65. Programmer Awareness Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! d, err := f.Stat()! }
  • 66. Programmer Awareness Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! f, err := f.Stat()! }
  • 67. Programmer Awareness Variable Re-declaration import "os"! Error: no new ! variables on left func main() {! side of := ! f, err := os.Open("somefile")! ! // handle error! ! ! f, err := f.Stat()! } Hmm.. I think you re-used the variable f by mistake!
  • 68. Programmer Awareness Variable Re-declaration import "os"! ! func main() {! ! f, err := os.Open("somefile")! ! // handle error! ! ! f, err = f.Open("other file")! } Re-assign ! explicitly.. 
  • 69.
  • 70. With Great Power Comes Great Responsibility
  • 73. Lets Go a little more! type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Dimensions)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } Type Declaration
  • 74. Lets Go a little more! type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Dimensions)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } Exported Array
  • 75. Lets Go a little more! type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Dimensions)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } Exported Array The size in Array is part of the type! [2]float32 != [3]float32
  • 76. Lets Go a little more! type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Dimensions)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } Embedding! (Not inheritance)
  • 77. Lets Go a little more! type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Dimensions)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } hotel.Dimensions and not hotel.Hall.Dimensions
  • 78. Lets Go a little more! func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Name)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } Dimensions)!
  • 79. Lets Go a little more! func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Name)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! }
  • 80. Programmer Awareness type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Name)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! }
  • 81. Programmer Awareness type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Name)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! } Which Name should I use? Error: Ambiguous selector hotel.Name!
  • 82. Programmer Awareness type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Name)Hall.! Name)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! }
  • 83. Programmer Awareness type Layout struct {! ! Name string! Capacity int! }! ! type Hall struct {! ! Name string! ! Dimensions [2]float32! }! ! type Hotel struct {! ! Location string! ! Hall! ! Layout! } func main() {! ! hotel := Hotel{}! ! fmt.Println(hotel.Hall.Name)! ! ! h := make(map[string]Hotel)! ! ! for name, _ := range h {! ! ! fmt.Println(name)! ! }! }
  • 84. Modules in Ruby module Layout! def manager! p "Layout Manager"! end! end! ! module Hall! def manager! p "Hall Manager"! end! end! ! class Hotel! include Layout! include Hall! end def main! hotel = Hotel.new! p hotel.manager! end
  • 85. Modules in Ruby module Layout! def manager! p "Layout Manager"! end! end! ! module Hall! def manager! p "Hall Manager"! end! end! ! class Hotel! include Layout! include Hall! end def main! hotel = Hotel.new! p hotel.manager! end Which language is this dude?
  • 86. Include modules in order! https://flic.kr/p/e7SnAa
  • 87. Programmer Awareness Iterating a Hash hotels := make(map[string]Hotel)! ! for name, _ := range hotels {! ! fmt.Println(name)! }
  • 88. Programmer Awareness Iterating a Hash hotels := make(map[string]Hotel)! ! for name, _ := range hotels {! ! fmt.Println(name)! } Map of strings and Hotels
  • 89. Programmer Awareness Iterating a Hash hotels := make(map[string]Hotel)! ! for name, _ := range hotels {! ! fmt.Println(name)! } Easy iteration syntax!
  • 90. Programmer Awareness Iterating a Hash hotels := make(map[string]Hotel)! ! for name, _ := range hotels {! ! fmt.Println(name)! } Blank Identifier - ignore value
  • 91. Programmer Awareness Iterating a Hash hotels := make(map[string]Hotel)! ! for name, _ := range hotels {! ! fmt.Println(name)! }
  • 92. Programmer Awareness Iterating a Hash hotels := make(map[string]Hotel)! ! for name, _ := range hotels {! ! fmt.Println(name)! } Bad practice! ! I’ll randomise the order!
  • 95. Pushing some Goodies into Ruby https://flic.kr/p/awu6ZA
  • 96. Defer mu sync.Mutex! ! func foo() {! mu.Lock()! defer mu.unLock()! // do something...! } https://flic.kr/p/awu6ZA
  • 97. Defer func trace(s string) { fmt.Println("entering:", s) }! func untrace(s string) { fmt.Println("leaving:", s) }! ! func a() {! trace("a")! defer untrace("a")! // do something....! } https://flic.kr/p/awu6ZA
  • 98. Concurrency Parallelism Multi-core Processing https://flic.kr/p/awu6ZA
  • 99. Example - Relay Race • 4 legs of the race • Each leg does processing concurrently. • Completion should be in order. (pass the baton)
  • 100. Concurrent Example Leg 1 Leg 2 Leg 3 Leg 4
  • 101. Concurrent Processing Leg 1 Leg 2 Leg 3 Leg 4 CPU churn - CPU time consuming operation.
  • 102. Completion Order Leg 1 Leg 2 Leg 3 Leg 4
  • 103. Completion Order Leg 1 Leg 2 Leg 3 Leg 4
  • 104. Completion Order Leg 1 Leg 2 Leg 3 Leg 4
  • 105. Completion Order Leg 1 Leg 2 Leg 3 Leg 4
  • 106.
  • 107.
  • 108. CSP! Communicating Sequential Processes https://flic.kr/p/6MwYFo https://flic.kr/p/awu6ZA
  • 109. CSP! Communicating Sequential Processes since 1978 !! https://flic.kr/p/awu6ZA https://flic.kr/p/6MwYFo
  • 110. package main ! import ( "fmt" "runtime" "sync" ) ! var wg sync.WaitGroup ! /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1
  • 111. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() }
  • 112. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) ! for i := 1; i < 5; i++ {! go run(i, baton)! }! ! ! ! ! // start the race! baton <- 1! ! // wait for relay to finish! wg.Wait()! }
  • 113. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) ! for i := 1; i < 5; i++ {! go run(i, baton)! }! ! ! ! ! // start the race! baton <- 1! ! // wait for relay to finish! wg.Wait()! } A channel that accepts an int
  • 114. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) ! for i := 1; i < 5; i++ {! go run(i, baton)! }! ! ! ! ! // start the race! baton <- 1! ! // wait for relay to finish! wg.Wait()! } Go Routine
  • 115. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) ! for i := 1; i < 5; i++ {! go run(i, baton)! }! ! ! ! ! // start the race! baton <- 1! ! // wait for relay to finish! wg.Wait()! } Writing to a channel
  • 116. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) ! for i := 1; i < 5; i++ {! go run(i, baton)! }! ! ! ! ! // start the race! baton <- 1! ! // wait for relay to finish! wg.Wait()! } A WaitGroup - wait for 4 events!
  • 117. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() }
  • 118. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func run(leg int, baton chan int) { defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) ! ! ! // Massive CPU churn! ! ! for count := 0; count < 300; count++ {! ! ! ! for char := 0; char < 30000; char++ {! ! ! ! fmt.Printf("")! ! ! ! }! ! ! }! fmt.Printf("Leg %d.. churned, waiting to ! ! ! check_baton(leg, baton)! }
  • 119. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func run(leg int, baton chan int) { defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) Done for WaitGroup ! ! ! // Massive CPU churn! ! ! for count := 0; count < 300; count++ {! ! ! ! for char := 0; char < 30000; char++ {! ! ! ! fmt.Printf("")! ! ! ! }! ! ! }! fmt.Printf("Leg %d.. churned, waiting to ! ! ! check_baton(leg, baton)! }
  • 120. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() }
  • 121. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func check_baton(leg int, baton chan int) {! ! ! for value := range baton {! ! ! ! switch value {! ! ! ! ! case leg:! ! ! ! ! ! // pass the baton! ! ! ! ! ! fmt.Println("Finished leg ", leg)! ! ! ! ! ! if leg == 4 {! ! ! ! ! ! ! close(baton)! ! ! ! ! ! } else {! ! ! ! ! ! ! ! baton <- leg + 1! ! ! ! ! ! }! ! ! ! ! ! return! ! ! ! ! default:! ! ! ! ! ! // ignore! ! ! ! ! ! baton <- value! ! ! ! }! ! ! }! }
  • 122. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func check_baton(leg int, baton chan int) {! ! ! for value := range baton {! ! ! ! switch value {! ! ! ! ! case leg:Read ! or block on a ! ! ! ! ! // pass the channel baton! ! ! ! ! ! fmt.Println("Finished leg ", leg)! ! ! ! ! ! if leg == 4 {! ! ! ! ! ! ! close(baton)! ! ! ! ! ! } else {! ! ! ! ! ! ! ! baton <- leg + 1! ! ! ! ! ! }! ! ! ! ! ! return! ! ! ! ! default:! ! ! ! ! ! // ignore! ! ! ! ! ! baton <- value! ! ! ! }! ! ! }! }
  • 123. Channels in action p!ackage main import ( "fmt" "runtime" "sync" )! v!ar wg sync.WaitGroup /* * Each go-routine sleeps at random(1-5) seconds. * This is simulating long working process * Then we finish in order */ func check_baton(leg int, baton chan int) { for value := range baton { switch value { case leg: // pass the baton fmt.Println("Finished leg ", leg) if leg == 4 { close(baton) } else { baton <- leg + 1 } return default: // ignore baton <- value } } }! func run(leg int, baton chan int) { ! defer wg.Done() fmt.Printf("Leg %d.. churningn", leg) // Massive CPU churn for count := 0; count < 300; count++ { for char := 0; char < 30000; char++ { fmt.Printf("") } ! } fmt.Printf("Leg %d.. churned, waiting to exitn", leg) ! check_baton(leg, baton) }! func main() { runtime.GOMAXPROCS(4) ! baton := make(chan int) wg.Add(4) for i := 1; i < 5; i++ { ! go run(i, baton) } ! // start the race baton <- 1 // wait for relay to finish wg.Wait() } func check_baton(leg int, baton chan int) {! ! ! for value := range baton {! ! ! ! switch value {! ! ! ! ! case leg:! ! ! ! ! ! // pass the baton! ! ! ! ! ! fmt.Println("Finished leg ", leg)! ! ! ! ! ! if leg == 4 {! ! ! ! ! ! ! close(baton)! ! ! ! ! ! } else {! ! ! ! ! ! ! ! baton <- leg + 1! ! ! ! ! ! }! ! ! ! ! ! return! ! ! ! ! default:! ! ! ! ! ! // ignore! ! ! ! ! ! baton <- value! ! ! ! }! ! ! }! }
  • 124. The Big Fight https://flic.kr/p/9AeqD2
  • 125. Generics? Convenient Too early still. interface{} https://flic.kr/p/9AeqD2
  • 126. Keywords! Nah.. no rules, https://flic.kr/p/9AeqD2 rules! You need’em bro
  • 127. GIL https://flic.kr/p/9AeqD2  Compiled language FTW
  • 128. Extending & Embedding https://flic.kr/p/9AeqD2 Yeah Nope. ! Only Cgo
  • 130.
  • 131. Emergency Instructions ! OR ! Lecture In Aerodynamics
  • 134.
  • 135. Traction Control! Fuel Efficiency! Aerodynamics! Tyre Temperature
  • 136. Traction Control! Fuel Efficiency! Aerodynamics! Tyre Temperature
  • 137. “ Ruby is for developers Go is for programmers ” @gautamrege @joshsoftware