why go is an important programming language

51
Copyright © 2013 Russel Winder 1 Why Go is an Important Language Prof Russel Winder email: [email protected] xmpp: [email protected] twitter: russel_winder

Upload: russel-winder

Post on 01-Dec-2014

1.760 views

Category:

Technology


1 download

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:20

TRANSCRIPT

Page 1: Why Go is an important programming language

Copyright © 2013 Russel Winder 1

Why Go is anImportant Language

Prof Russel Winder

email: [email protected]: [email protected]

twitter: russel_winder

Page 2: Why Go is an important programming language

Copyright © 2013 Russel Winder 2

Interstitial Advertisement

?

Page 3: Why Go is an important programming language

Copyright © 2013 Russel Winder 3

controversial adjective of, pertaining to, or characteristic of controversy; polemical

Page 4: Why Go is an important programming language

Copyright © 2013 Russel Winder 4

controversy noun dispute, argument, or debate, especially one concerning a matter about which there is strong disagreement

Page 5: Why Go is an important programming language

Copyright © 2013 Russel Winder 5

polemic noun a strong verbal or written attack on someone or something

Page 6: Why Go is an important programming language

Copyright © 2013 Russel Winder 6

Go, made public late 2009.

Page 7: Why Go is an important programming language

Copyright © 2013 Russel Winder 7

It's a better C.

Page 8: Why Go is an important programming language

Copyright © 2013 Russel Winder 8

Strong, static type checking.

Page 9: Why Go is an important programming language

Copyright © 2013 Russel Winder 9

Garbage collected.

Page 10: Why Go is an important programming language

Copyright © 2013 Russel Winder 10

Statically linked.

Page 11: Why Go is an important programming language

Copyright © 2013 Russel Winder 11

Aware of DVCS repositories.

Page 12: Why Go is an important programming language

Copyright © 2013 Russel Winder 12

No classes.

Page 13: Why Go is an important programming language

Copyright © 2013 Russel Winder 13

Separation of state and behaviour.

Page 14: Why Go is an important programming language

Copyright © 2013 Russel Winder 14

Focus on modern, multicore hardware.

Page 15: Why Go is an important programming language

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.

Page 16: Why Go is an important programming language

Copyright © 2013 Russel Winder 16

Parallelism is performance improvement.

Performance improvement requires parallelism.

Page 17: Why Go is an important programming language

Copyright © 2013 Russel Winder 17

People should tremble in fear

at the prospect of using

mutableshared-memorymultithreading.

Page 18: Why Go is an important programming language

Copyright © 2013 Russel Winder 18

Locks deny parallelism.

The whole purpose of a lock is toprevent parallelism.

Page 19: Why Go is an important programming language

Copyright © 2013 Russel Winder 19

Locks are needed only ifthere is mutable shared state.

Page 20: Why Go is an important programming language

Copyright © 2013 Russel Winder 20

Avoid mutable shared state.

Page 21: Why Go is an important programming language

Copyright © 2013 Russel Winder 21

Use processes and message passing.

Page 22: Why Go is an important programming language

Copyright © 2013 Russel Winder 22

It's all easier if processesare single threaded.

Page 23: Why Go is an important programming language

Copyright © 2013 Russel Winder 23

Applications and tools programmersneed computational models with

integrated synchronization.

Page 24: Why Go is an important programming language

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.

Page 25: Why Go is an important programming language

Copyright © 2013 Russel Winder 25

Data ParallelismTransform a sequence to another sequence where all individual actions happen at the same time.

Page 26: Why Go is an important programming language

Copyright © 2013 Russel Winder 26

ActorsIndependent processes communicating via asynchronous exchange of messages

Page 27: Why Go is an important programming language

Copyright © 2013 Russel Winder 27

DataflowOperators connected by channels with activity triggered by arrival of data on the channels.

Page 28: Why Go is an important programming language

Copyright © 2013 Russel Winder 28

CSPSequential processes connected by channels using synchronous message exchange (rendezvous).

Page 29: Why Go is an important programming language

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.

Page 30: Why Go is an important programming language

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.

Page 31: Why Go is an important programming language

Copyright © 2013 Russel Winder 31

Example.

Page 32: Why Go is an important programming language

Copyright © 2013 Russel Winder 32

Page 33: Why Go is an important programming language

Copyright © 2013 Russel Winder 33

What is the Value of ?

Easy, it's known exactly.

It's .

Obviously.

Page 34: Why Go is an important programming language

Copyright © 2013 Russel Winder 34

It's simples Александр Орлов 2009

Page 35: Why Go is an important programming language

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

Page 36: Why Go is an important programming language

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.

Page 37: Why Go is an important programming language

Copyright © 2013 Russel Winder 37

Because addition is commutative andassociative, expression can be

decomposed into sums of partial sums.

Page 38: Why Go is an important programming language

Copyright © 2013 Russel Winder 38

a + b + c + d + e + f

=

( a + b ) + ( c + d ) + ( e + f )

Page 39: Why Go is an important programming language

Copyright © 2013 Russel Winder 39

Scatter – Gather

map reduce

Page 40: Why Go is an important programming language

Copyright © 2013 Russel Winder 40

Code!

Page 41: Why Go is an important programming language

Copyright © 2013 Russel Winder 41

If you want the code, clone the Git repository:

http://www.russel.org.uk/Git/Pi_Quadrature.git

Page 42: Why Go is an important programming language

Copyright © 2013 Russel Winder 42

Or if you just want to browse:

http://www.russel.org.uk/gitweb

Page 43: Why Go is an important programming language

Copyright © 2013 Russel Winder 43

Multicore and multiprocessor are nowthe norm, not the exception.

Page 44: Why Go is an important programming language

Copyright © 2013 Russel Winder 44

Parallelism only matters ifcomputational performance matters.

Page 45: Why Go is an important programming language

Copyright © 2013 Russel Winder 45

Unstructured synchronizationof concurrent systems

is not a feasible approach.

Page 46: Why Go is an important programming language

Copyright © 2013 Russel Winder 46

Actors, CSP, Dataflow, andData parallelismare the future of

applications structure.

Page 47: Why Go is an important programming language

Copyright © 2013 Russel Winder 47

Passing messages betweenprocesses is the way forward.

Page 48: Why Go is an important programming language

Copyright © 2013 Russel Winder 48

Shared memory concurrencyis a dead end for applications.

Page 49: Why Go is an important programming language

Copyright © 2013 Russel Winder 49

Goroutines

and

channels

Page 50: Why Go is an important programming language

Copyright © 2013 Russel Winder 50

Interstitial Advertisement

?

Page 51: Why Go is an important programming language

Copyright © 2013 Russel Winder 51

Why Go is anImportant Language

Prof Russel Winder

email: [email protected]: [email protected]

twitter: russel_winder