why go is an important programming language
DESCRIPTION
A short presentation given at the inaugural meeting of the Go London User Group http://www.meetup.com/Go-London-User-Group/ 2013-03-27T20:20TRANSCRIPT
Copyright © 2013 Russel Winder 1
Why Go is anImportant Language
Prof Russel Winder
email: [email protected]: [email protected]
twitter: russel_winder
Copyright © 2013 Russel Winder 2
Interstitial Advertisement
?
Copyright © 2013 Russel Winder 3
controversial adjective of, pertaining to, or characteristic of controversy; polemical
Copyright © 2013 Russel Winder 4
controversy noun dispute, argument, or debate, especially one concerning a matter about which there is strong disagreement
Copyright © 2013 Russel Winder 5
polemic noun a strong verbal or written attack on someone or something
Copyright © 2013 Russel Winder 6
Go, made public late 2009.
Copyright © 2013 Russel Winder 7
It's a better C.
Copyright © 2013 Russel Winder 8
Strong, static type checking.
Copyright © 2013 Russel Winder 9
Garbage collected.
Copyright © 2013 Russel Winder 10
Statically linked.
Copyright © 2013 Russel Winder 11
Aware of DVCS repositories.
Copyright © 2013 Russel Winder 12
No classes.
Copyright © 2013 Russel Winder 13
Separation of state and behaviour.
Copyright © 2013 Russel Winder 14
Focus on modern, multicore hardware.
Copyright © 2013 Russel Winder 15
Concurrency is a tool for structuring execution where asingle processor is used by multiple computations.
Parallelism is about making a computation completefaster than using a single processor.
Copyright © 2013 Russel Winder 16
Parallelism is performance improvement.
Performance improvement requires parallelism.
Copyright © 2013 Russel Winder 17
People should tremble in fear
at the prospect of using
mutableshared-memorymultithreading.
Copyright © 2013 Russel Winder 18
Locks deny parallelism.
The whole purpose of a lock is toprevent parallelism.
Copyright © 2013 Russel Winder 19
Locks are needed only ifthere is mutable shared state.
Copyright © 2013 Russel Winder 20
Avoid mutable shared state.
Copyright © 2013 Russel Winder 21
Use processes and message passing.
Copyright © 2013 Russel Winder 22
It's all easier if processesare single threaded.
Copyright © 2013 Russel Winder 23
Applications and tools programmersneed computational models with
integrated synchronization.
Copyright © 2013 Russel Winder 24
ActorsIndependent processes communicating via asynchronous exchange of messages
CSPSequential processes connected by channels using synchronous message exchange (rendezvous).
DataflowOperators connected by channels with activity triggered by arrival of data on the channels.
Data ParallelismTransform a sequence to another sequence where all individual actions happen at the same time.
Copyright © 2013 Russel Winder 25
Data ParallelismTransform a sequence to another sequence where all individual actions happen at the same time.
Copyright © 2013 Russel Winder 26
ActorsIndependent processes communicating via asynchronous exchange of messages
Copyright © 2013 Russel Winder 27
DataflowOperators connected by channels with activity triggered by arrival of data on the channels.
Copyright © 2013 Russel Winder 28
CSPSequential processes connected by channels using synchronous message exchange (rendezvous).
Copyright © 2013 Russel Winder 29
ActorsIndependent processes communicating via asynchronous exchange of messages
CSPSequential processes connected by channels using synchronous message exchange (rendezvous).
DataflowOperators connected by channels with activity triggered by arrival of data on the channels.
Data ParallelismTransform a sequence to another sequence where all individual actions happen at the same time.
Copyright © 2013 Russel Winder 30
Active ObjectsAn object that is actually an actor but looks like a full service object.
AgentsA wrapper for some shared mutable state.
Software Transactional MemoryWrappers for mutable values that uses transactions rather than locks.
Fork/JoinAn toolkit for tree structured concurrency and parallelism.
Copyright © 2013 Russel Winder 31
Example.
Copyright © 2013 Russel Winder 32
Copyright © 2013 Russel Winder 33
What is the Value of ?
Easy, it's known exactly.
It's .
Obviously.
Copyright © 2013 Russel Winder 34
It's simples Александр Орлов 2009
Copyright © 2013 Russel Winder 35
Approximating
● What is it's value represented as a floating point number?● We can only obtain an approximation.● A plethora of possible algorithms to choose from, a
popular one is to employ the following integral equation.
4=∫0
1 1
1x2dx
Copyright © 2013 Russel Winder 36
One Possible Algorithm
● Use quadrature to estimate the value of the integral – which is the area under the curve.
=4n∑i=1
n 1
1i−0.5n
2
With n = 3 not much to do, but potentially lots of error. Use n = 107 or n = 109?
Embarrassingly parallel.
Copyright © 2013 Russel Winder 37
Because addition is commutative andassociative, expression can be
decomposed into sums of partial sums.
Copyright © 2013 Russel Winder 38
a + b + c + d + e + f
=
( a + b ) + ( c + d ) + ( e + f )
Copyright © 2013 Russel Winder 39
Scatter – Gather
map reduce
Copyright © 2013 Russel Winder 40
Code!
Copyright © 2013 Russel Winder 41
If you want the code, clone the Git repository:
http://www.russel.org.uk/Git/Pi_Quadrature.git
Copyright © 2013 Russel Winder 42
Or if you just want to browse:
http://www.russel.org.uk/gitweb
Copyright © 2013 Russel Winder 43
Multicore and multiprocessor are nowthe norm, not the exception.
Copyright © 2013 Russel Winder 44
Parallelism only matters ifcomputational performance matters.
Copyright © 2013 Russel Winder 45
Unstructured synchronizationof concurrent systems
is not a feasible approach.
Copyright © 2013 Russel Winder 46
Actors, CSP, Dataflow, andData parallelismare the future of
applications structure.
Copyright © 2013 Russel Winder 47
Passing messages betweenprocesses is the way forward.
Copyright © 2013 Russel Winder 48
Shared memory concurrencyis a dead end for applications.
Copyright © 2013 Russel Winder 49
Goroutines
and
channels
Copyright © 2013 Russel Winder 50
Interstitial Advertisement
?
Copyright © 2013 Russel Winder 51
Why Go is anImportant Language
Prof Russel Winder
email: [email protected]: [email protected]
twitter: russel_winder