More Related Content
More from Russel Winder (20)
Switch to Python 3…now…immediately
- 1. Switch to Python 3…
Now…
Immediately!
Prof Russel Winder
http://www.russel.org.uk
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: @russel_winder
Copyright © 2013 Russel Winder 1
- 3. polemic
noun
a strong verbal or written attack on someone or something
Copyright © 2013 Russel Winder 3
- 5. 2.6 2.7
2.5
2.4
2.3
2.2
Copyright © 2013 Russel Winder 5
- 6. 3.3
3.2
3.1
3.0
Copyright © 2013 Russel Winder 6
- 8. So what's the problem?
● Python 2 remains the default Python.
● Too many people and organizations are far too
afraid of change.
Why do people and organizations
become so afraid of change?
Copyright © 2013 Russel Winder 8
- 9. So what's the solution?
● Python Software Foundation (PSF) should declare
Python 3 the default Python immediately.
People and organizations can implement this now:
python → python2
replaced by:
python → python3
Copyright © 2013 Russel Winder 9
- 10. But…world, we have a problem…
● …a few influential organizations are telling people
not to use Python 3 but to stay with Python 2,
and…
Afraid of change?
● …some crucial projects can't or won't get Python 3
versions out.
Afraid of change?
Many projects are now both Python 2 and
Python 3 or getting there very rapidly.
Copyright © 2013 Russel Winder 10
- 12. Or at least ensure their codebases
run under both Python 2 and Python 3.
Copyright © 2013 Russel Winder 12
- 13. Being Python 2 and 3 compatible
● 2to3 not useful, its a one shot transform tool.
● six package might be useful in parts, and/or…
● …modernize package might help, but…
● …is manual the best?
Copyright © 2013 Russel Winder 13
- 14. Embrace
managed and controlled
change.
Copyright © 2013 Russel Winder 14
- 17. Python 2 is a dead end.
Python 3 is the developing future.
Copyright © 2013 Russel Winder 17
- 18. print(x)
exec(x)
Copyright © 2013 Russel Winder 18
- 20. from __future__ import (
division,
absolute_import,
print_function,
unicode_literals,
)
Copyright © 2013 Russel Winder 20
- 21. x = [x * x for x in range(100) if x % 10 == 0]
Copyright © 2013 Russel Winder 21
- 22. x = {x * x for x in range(100) if x % 10 == 0}
Copyright © 2013 Russel Winder 22
- 23. x = {x: x * x for x in range(100) if x % 10 == 0}
Copyright © 2013 Russel Winder 23
- 24. Sadly (!) Python 2.7 is getting
backports of things from Python 3.
Copyright © 2013 Russel Winder 24
- 26. Python 2 is strict,
Python 3 is (sort of) lazy
Copyright © 2013 Russel Winder 26
- 27. map(lambda x: x * x,
filter(lambda x: x % 10 == 0, range(100))
Copyright © 2013 Russel Winder 27
- 28. range(x) tuple(range(x))
→
xrange(x) range(x)
Copyright © 2013 Russel Winder 28
- 29. Not Sequences, but Iterators
items
keys
values
iteritems
→ items
iterkeys keys
itervalues values
Copyright © 2013 Russel Winder 29
- 31. Python is under challenge
● Go is taking over from Python for many people.
● Native, not interpreted.
● Solid concurrency model – CSP
● D is hoping to take over from C, C++, Go, Python.
● Native, not interpreted.
● Solid concurrency models – actors, data parallelism
Copyright © 2013 Russel Winder 31
- 33. And native code programs are
way, way faster than Python programs.
Copyright © 2013 Russel Winder 33
- 34. Statically compiled languages catch errors at
compile time that are horrendous run
time bugs in dynamic languages.
Copyright © 2013 Russel Winder 34
- 35. Are you concurrent?
● Who's using thread?
● Who's using threading?
Copyright © 2013 Russel Winder 35
- 36. Are you parallel?
● Who's using thread?
● Who's using threading?
● Who's using multiprocessing?
Copyright © 2013 Russel Winder 36
- 37. At least IronPython and Jython
do not have a GIL as
CPython and PyPy do.
Copyright © 2013 Russel Winder 37
- 39. NB CSP stands for
Concurrent Sequential Processes
Copyright © 2011–2012 Russel Winder 39
- 40. Dataflow
Operators connected by
Actors channels with activity
Independent processes triggered by arrival of
communicating via data on the channels.
asynchronous exchange
of messages
CSP
Sequential processes
connected by channels
using synchronous message
exchange (rendezvous).
Copyright © 2011–2012 Russel Winder 40
- 41. Actors
Independent processes
communicating via
asynchronous exchange
of messages
Copyright © 2011–2012 Russel Winder 41
- 42. Dataflow
Operators connected by
channels with activity
triggered by arrival of
data on the channels.
Copyright © 2011–2012 Russel Winder 42
- 43. CSP
Sequential processes
connected by channels
using synchronous message
exchange (rendezvous).
Copyright © 2011–2012 Russel Winder 43
- 44. Data Parallelism
Transform a sequence to
another sequence where all
individual actions happen
at the same time.
Copyright © 2013 Russel Winder 44
- 47. Concurrent.futures
● Python 3.2 package to abstract over threads and
processes to give an asynchronous function call and
future system.
cf. futures package for Python 2.
Copyright © 2013 Russel Winder 47
- 51. There are no real reasons
to stay with Python 2…
Copyright © 2013 Russel Winder 51
- 52. …so Python 3 should be
Considered mandatory.
Copyright © 2013 Russel Winder 52
- 54. Problem
Python 3
Python 2
Is there a problem, the solution to which can
be coded in Python 2, but not better in Python 3?
Copyright © 2013 Russel Winder 54
- 56. Switch to Python 3…
Now…
Immediately!
Prof Russel Winder
http://www.russel.org.uk
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: @russel_winder
Copyright © 2013 Russel Winder 56