Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Job Security (in Python) (Christopher Neugebauer)
PyCon Canada
August 25, 2013
Education
2
470
Job Security (in Python) (Christopher Neugebauer)
PyCon Canada
August 25, 2013
Tweet
Share
More Decks by PyCon Canada
See All by PyCon Canada
pyconca
0
330
pyconca
0
160
pyconca
2
90
pyconca
0
180
pyconca
0
68
pyconca
0
85
pyconca
0
920
pyconca
0
130
pyconca
2
77
Other Decks in Education
See All in Education
matleenalaakso
1
11k
ailaboocu
0
250
matleenalaakso
0
2.9k
pilatestonic
PRO
0
120
ailaboocu
0
120
strikr
1
260
karte
0
300
matleenalaakso
4
790
mac03nd
0
350
birdhiro
0
220
taisso
1
1.2k
salvemaria
0
200
Featured
See All Featured
andyhume
63
3.7k
jensimmons
207
10k
3n
163
22k
brad_frost
157
6.4k
akmur
252
19k
chriscoyier
498
130k
yeseniaperezcruz
302
31k
phodgson
87
3.9k
trallard
14
720
lynnandtonic
272
16k
robhawkes
52
2.8k
mojombo
359
62k
Transcript
Hello Canadia!
Job Security (in Python) Christopher Neugebauer @chrisjrn http://chris.neugebauer.id.au
Hello!
Why do people code Python?
“Readability” -- Raymond Hettinger, PyCon US 2013
“Readability Counts” -- Tim Peters, “The Zen of Python” (import
this)
PEP 0008 “Style Guide for Python Code”
None
Readability Sucks.
1. People can comprehend your code.
2. You can maintain your own code.
3. Your code will be more readily reusable.
THIS IS ALL BAD.
How do I write unmaintainable code?
1) Obvious variable names
1) Obvious (to you) variable names
• Callables: Superheroes • Classes: Musical characters • Strings: Famous
actors • Numbers: Movie characters
MerryPoppins.captain_america(matt_damon, james_bond)
Spiderman.spiderman(spiderman)
2) Metaprogramming
class Collection(Magic): def get_spam(self): return self.spam def set_spam(self, default): self.spam
= default
>>> c = Collection() >>> c.set_spam(“eggs”)
>>> c = Collection() >>> c.set_spam(“eggs”) Traceback (most recent call
last): File "<stdin>", line 1, in <module> File "<stdin>", line 10, in __getattribute__ TypeError: instancemethod expected at least 2 arguments, got 0
Help on Collection in module __main__ object: class Collection(Magic) |
Method resolution order: | Collection | Magic | __builtin__.object | | Methods defined here: | | get_spam(self) | | set_spam(self, default)
TRANSLATE = (("get","_bork_"), ("set","_bork_"), ("canhas" , "get"), ("ihasa" , "set"))
class Magic(object): def __getattribute__(self, attribute): oa = attribute for (key,val) in TRANSLATE: attribute = attribute.replace(key, val) try: return object. __getattribute__(self,attribute) except AttributeError: return type(object. __getattribute__(self, oa))
c.ihasa_spam("foo") -> c.set_spam(“foo”) c.canhas_spam() -> c.get_spam()
3) Monkey patching
“A batteries-included standard library” -- Raymond Hettinger, PyCon US 2013
Roll your own standard library
>>> import math >>> math.cos(0)
>>> import math >>> math.cos(0) 0.0
>>> import magic >>> import math >>> math.cos(0) 0.0
import math math.cos, math.sin = math.sin, math.cos
- End -
This talk was a joke.
Don’t do this.
The end. Christopher Neugebauer @chrisjrn http://chris.neugebauer.id.au