4. package
organisation import
var, const, type
declaration
func, interface, map, struct, chan
if ... else
switch ... case ... fallthrough ... default
select ... case
control flow for
for ... range
break, continue
go, goto, defer, return
11. class Counter
attr_writer :count
def initialize
@count = 0
end
def Tick
@count += 1
end
end
class DoubleCounter < Counter
def Tick
super
@count += 1
end
end
n = new(DoubleCounter)
puts n.Tick
puts n.superclass.Tick
13. class Counter
attr_writer :count
def initialize
@count = 0
end
def Tick
@count += 1
end
end
class DoubleCounter < Counter
def Tick
super
@count += 1
end
end
n = new(DoubleCounter)
puts n.Tick
puts n.superclass.Tick
15. class Counter
attr_writer :count
def initialize
@count = 0
end
def Tick
@count += 1
end
end
class DoubleCounter < Counter
def Tick
super
@count += 1
end
end
n = new(DoubleCounter)
puts n.Tick
puts n.superclass.Tick
17. class Counter
attr_writer :count
def initialize
@count = 0
end
def Tick
@count += 1
end
end
class DoubleCounter < Counter
def Tick
super
@count += 1
end
end
n = new(DoubleCounter)
puts n.Tick
puts n.superclass.Tick
18. class Counter
attr_writer :count
def initialize
@count = 0
end
def Tick
@count += 1
end
end
class DoubleCounter < Counter
def Tick
super
@count += 1
end
end
n = new(DoubleCounter)
puts n.Tick
puts n.superclass.Tick
19. class Counter
attr_writer :count
def initialize
@count = 0
end
def Tick
@count += 1
end
end
class DoubleCounter < Counter
def Tick
super
@count += 1
end
end
n = new(DoubleCounter)
puts n.Tick
puts n.superclass.Tick
20. instance inherited
class class
expressed
type
modules
21. superclass modules
class modules
message
instance
22. superclass modules
class modules
type asserted
instance
24. down a rabbit hole
instances are their own classes
and all classes are mutable at runtime
25. down a rabbit hole
instances are their own classes
all classes are mutable at runtime
so inheritance pathways can be altered
26. down a rabbit hole
instances are their own classes
and all classes are mutable at runtime
so inheritance pathways can be altered
making Ruby very flexible
27. down a rabbit hole
instances are their own classes
and all classes are mutable at runtime
so inheritance pathways can be altered
making Ruby very flexible
at the cost of type uncertainty
28. down a rabbit hole
instances are their own classes
and all classes are mutable at runtime
so inheritance pathways can be altered
making Ruby very flexible
at the cost of type uncertainty
which really bugs computer scientists
71. down a rabbit hole
an object has known static type
this fixed type is determined at linking
72. down a rabbit hole
an object has known static type
this fixed type is determined at linking
no new types can be created at runtime
73. down a rabbit hole
an object has known static type
this fixed type is determined at linking
no new types can be created at runtime
so dynamism is bounded to a fixed set
74. down a rabbit hole
an object has known static type
this fixed type is determined at linking
no new types can be created at runtime
so dynamism is bounded to this fixed set
and computer scientists are happier
211. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
212. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
213. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
214. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
215. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
216. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
217. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func() {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-c) 0110011101011010
}
}()
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
218. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
219. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
220. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
221. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
222. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
223. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
224. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
225. package main
import "fmt"
func main() {
var c chan int
c = make(chan int)
limit := 16
go func(in chan int) {
for i := limit; i > 0; i-- { produces:
fmt.Print(<-in) 0110011101011010
}
}(c)
for i := limit; i > 0; i-- {
select {
case c <- 0:
case c <- 1:
}
}
}
226. func main() {
var c chan int
c = make(chan int, 16)
go func() {
for i := 16; i > 0; i-- {
fmt.Print(<-c)
} produces:
}()
0110011101011010
go func() {
select {
case c <- 0:
case c <- 1:
}
}()
for {}
}
227. func main() {
var c chan int
c = make(chan int, 16)
go func() {
for i := 16; i > 0; i-- {
fmt.Print(<-c)
} produces:
}()
0110011101011010
go func() {
select {
case c <- 0:
case c <- 1:
}
}()
for {}
}
228. func main() {
var c chan int
c = make(chan int, 16)
go func() {
for i := 16; i > 0; i-- {
fmt.Print(<-c)
} produces:
}()
0110011101011010
go func() {
select {
case c <- 0:
case c <- 1:
}
}()
for {}
}
229. func main() {
var c chan int
c = make(chan int, 16)
go func() {
for i := 16; i > 0; i-- {
fmt.Print(<-c)
} produces:
}()
0110011101011010
go func() {
select {
case c <- 0:
case c <- 1:
}
}()
for {}
}
230. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
231. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
232. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
233. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
234. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
235. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
236. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
237. package generalise
type SignalSource func(status chan bool)
func Wait(s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
<-done
}
func WaitAll(count int, s SignalSource) {
done := make(chan bool)
defer close(done)
go s(done)
for i := 0; i < count; i++ {
<- done
}
}
238. type Iteration func(k, x interface{}) bool
func (i Iteration) apply(k, v interface{}, c chan bool) {
go func() {
c <-i(k, v)
}()
}
func (f Iteration) Each(c interface{}) {
switch c := ValueOf(c); c.Kind() {
case Slice: WaitAll(c.Len(), SignalSource(func(done chan bool) {
for i := 0; i < c.Len(); i++ {
f.apply(i, c.Elem(i).Interface(), done) }}))
case Map: WaitAll(c.Len(), SignalSource(func(done chan bool) {
for _, k := range c.Keys() {
f.apply(k, c.Elem(k).Interface(), done) }}))
}
}
239. type Iteration func(k, x interface{}) bool
func (i Iteration) apply(k, v interface{}, c chan bool) {
go func() {
c <-i(k, v)
}()
}
func (f Iteration) Each(c interface{}) {
switch c := ValueOf(c); c.Kind() {
case Slice: WaitAll(c.Len(), SignalSource(func(done chan bool) {
for i := 0; i < c.Len(); i++ {
f.apply(i, c.Elem(i).Interface(), done) }}))
case Map: WaitAll(c.Len(), SignalSource(func(done chan bool) {
for _, k := range c.Keys() {
f.apply(k, c.Elem(k).Interface(), done) }}))
}
}