Created
April 30, 2012 21:59
-
-
Save rsdy/2563034 to your computer and use it in GitHub Desktop.
A prezentation about what is wrong with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{{ | |
╻ ╻╻ ╻╻ ╻ | |
┃╻┃┣━┫┗┳┛ | |
┗┻┛╹ ╹ ╹ | |
┏━┓╻ ╻╺┳╸╻ ╻┏━┓┏┓╻ | |
┣━┛┗┳┛ ┃ ┣━┫┃ ┃┃┗┫ | |
╹ ╹ ╹ ╹ ╹┗━┛╹ ╹ | |
┏━┓╻ ╻┏━╸╻┏ ┏━┓ | |
┗━┓┃ ┃┃ ┣┻┓┗━┓ | |
┗━┛┗━┛┗━╸╹ ╹┗━┛ | |
(and why I use it anyway) | |
}}} | |
{{{ | |
>>> from __future__ import braces | |
SyntaxError: not a chance (<input>, line 2) | |
}}} | |
{{{ | |
>>> def fun(param=[]): | |
... param.append('E!') | |
... print param | |
... | |
>>> fun(); fun(); | |
['E!'] | |
['E!', 'E!'] | |
}}} | |
{{{ | |
>>> True = False | |
>>> True | |
False | |
}}} | |
{{{ | |
>>> print('wat') | |
wat | |
>>> type(type) | |
<type 'type'> | |
>>> type(print) | |
File "<input>", line 1 | |
type(print) | |
^ | |
SyntaxError: invalid syntax | |
}}} | |
{{{ | |
>>> () | |
() | |
>>> (,) | |
File "<input>", line 1 | |
(,) | |
^ | |
SyntaxError: invalid syntax | |
>>> (1) | |
1 | |
>>> (1,) | |
(1,) | |
}}} | |
{{{ | |
>>> a = lambda: 1, 2 | |
>>> type(a) | |
<type 'tuple'> | |
>>> a = lambda: (1, 2) | |
>>> type(a) | |
<type 'function'> | |
}}} | |
{{{ | |
>>> with open('file', 'r') as f: | |
... while a = f.readline(): | |
File "<input>", line 2 | |
while a = f.readline(): | |
^ | |
SyntaxError: invalid syntax | |
}}} | |
{{{ | |
>>> with open('file', 'r') as f: | |
... for line in iter(f.readline, '\n'): | |
... print line | |
}}} | |
{{{ | |
>>> with open('file', 'r') as f: | |
... for line in iter(lambda: f.readline(10), '\n'): | |
... print line | |
}}} | |
{{{ | |
>>> class C(object): | |
... def f(self, param): | |
... print param, self | |
>>> C.f('e', 'h') | |
Traceback (most recent call last): | |
File "<input>", line 1, in <module> | |
TypeError: unbound method f() must be called with C instance as first argument (got str instance instead) | |
}}} | |
{{{ | |
>>> class C(object): | |
... a = '' | |
... def __init__(self, a): | |
... self.a = a | |
... def __repr__(self): | |
... return str(self.a) | |
... | |
>>> c1 = C(1) | |
>>> c2 = C(2) | |
>>> print c1, c2 | |
1 2 | |
}}} | |
{{{ | |
>>> class C(object): | |
... a={} | |
... def __init__(self, x): | |
... self.a[0]=x | |
... def __repr__(self): | |
... return str(self.a[0]) | |
... | |
>>> print [C(x) for x in range(5)] | |
[4, 4, 4, 4, 4] | |
}}} | |
{{{ | |
>>> 1.__class__ | |
File "<input>", line 1 | |
1.__class__ | |
^ | |
SyntaxError: invalid syntax | |
>>> (1).__class__ | |
<type 'int'> | |
}}} | |
{{{ | |
>>> len((1,2,3,4,5,6)) | |
>>> Item.query.count() | |
}}} | |
{{{ | |
│__abs__ __add__ __and__ │ | |
│__call__ __cmp__ __coerce__ │ | |
│__complex__ __contains__ __debug__ │ | |
│__div__ __divmod__ __doc__ │ | |
│__enter__ __eq__ __exit__ │ | |
│__float__ __floordiv__ __ge__ │ | |
│__get__ __getattr__ __getitem__│ | |
│__gt__ __hash__ __hex__ │ | |
│__import__( __index__ __init__ │ | |
│... __getattribute__ ? │ | |
}}} | |
{{{ | |
>>> import threading | |
>>> dir(threading.Thread) | |
['_Thread__bootstrap', ... | |
'getName', 'ident', 'isAlive', 'isDaemon', | |
'is_alive', 'join', 'name', 'run', | |
'setDaemon', 'setName', 'start'] | |
}}} | |
{{{ | |
>>> try: | |
... import cStringIO | |
... except: | |
... import StringIO | |
}}} | |
{{{ | |
So why I use it anyway? | |
}}} | |
{{{ | |
Generally clean syntax | |
* like writing pseudo-code | |
* list comprehensions | |
[huzbah(x) for x in xs if g(x)] | |
* generators | |
(huzbah(x) for x in xs if g(x)) | |
- lazy evaluation | |
* higher order functions | |
- filter(lambda x: x > 5, xs) | |
- map(lambda x: x**x, xs) | |
- reduce(lambda a, x: a*x, xs, 0) | |
}}} | |
{{{ | |
When I see a bird that walks like a duck and | |
swims like a duck and | |
quacks like a duck, | |
I call that bird a duck | |
}}} | |
{{{ | |
Multiple inheritance | |
* you may as well shoot yourself in the foot | |
* mixins in Ruby | |
}}} | |
{{{ | |
Reasonable resource usage | |
* Ruby 1.8, anyone? (1.9 is better) | |
* Still not Lua | |
* http://shootout.alioth.debian.org/ | |
}}} | |
{{{ | |
flask >> django >> ruby on rails | |
* less bloat | |
* less mvc | |
* less administration | |
* less dependency hell | |
}}} | |
{{{ | |
virtualenv env | |
source env/bin/activate | |
pip install antigravity | |
deactivate | |
}}} | |
// vim:set ft=python fdm=marker: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment