9. Bad if you need three Hollywood actors to understand some piece of code
d.addErrback(
lambda reason: later(delay).addCallback(
lambda _: retry(
fun, args, kwargs,
delay * factor, factor, retries – 1)))
http://www.avforums.com/movies/Swordfish-review_8968/screenshots.html
10. Clever
Magic
This is where
you want to be Beautiful
Fun
Boring
11. xml = xmlify(„restrictions‟, {
„offline‟: {
„limits‟: limits
}
})
return etree.tostring(xml, encoding=„utf-8‟)
def __repr__(self):
args = “, “.join(“%s=%r” % i
for i in self.__dict__.iteritems())
return “%s(%s)” % (self.__class__.__name__, args)
12. (sig.signature or None) and sig.signature.encode(„hex‟)
(names, avalues) = zip(*avalues) # unzip…
----- Meeting Notes (10/15/11 20:11) -----A talk about fun Python can be really fun Sometimes too fun Not amusing Not just list comprehensions Bottle, Pest, Itty, Flask, web.py
----- Meeting Notes (10/15/11 20:11) -----Who am I? Tommie Gannert Joined Spotify 2007 Team lead, Backend infrastructure 7 devs Shared components, simplifying development Communication Monitoring Storage Learned Python from scratch at Spotify Shell and awk scripting before 2.4 -- 2.6 Twisted
----- Meeting Notes (10/15/11 20:11) -----Timeline 2006 founded 2007 I joined, private beta 2008 We launched 2008-10-07 2009 libspotify 2009-04-07 2010 Embedded platforms 2011 USA launchMain office Stockholm NYC, GbgTech teams 15 tech teams incl Ops, POPS
----- Meeting Notes (10/15/11 20:11) -----What is fun? "I believe..." Minimum syntax obstruction *args, **kwargs Higher order functions Decorators, context managers Analogy: Going to the grocery store when there is no line Analogy: Having an exam on a subject you have known since you were five Paving the way for flow Good feeling Have the solution in your mind Something to achieve What is not fun? As a definition for this talk Almost evil things Constructors with side-effects Not C++ RAII Metaclasses Self-modifying code Modern greek Perl Python
----- Meeting Notes (10/15/11 20:11) -----Why am I here? Lots of Python at Spotify LoC-diagram C++ client PHP web Java playlist Not fair given shorter code
----- Meeting Notes (10/15/11 20:11) -----Easy and fun writing tools in Python Show you some snippets from the Spotify code base Not a huge amount Good and bad Fun can easily go into bad Example: Graph matching algorithm
----- Meeting Notes (10/15/11 20:11) -----Especially; you shouldn't have to comfort anyone reading your codeAn idea: We need empathyKeep the balance
----- Meeting Notes (10/15/11 20:11) -----Code easily deterioratesYou shouldn't need a group of famous actors to decipher a piece of codeThis code probably started out fun This is Twisted, with two nested lambdas later() and retry() are easy enough to understand Part of old playlist system
A picture like this can mean two things Either very satisfied, or doing nasty thingsThis diagram I borrowed from business developmentOn a fun scale, boring is at the bottom. Maybe it should even be on the negative side.Concatenating XML-stringsCounting wordsDoing some simple calculationAnyone can do them in any language and it’s just plain boringIf we step up a notch, we come to the beautiful stageThis could be the use of context managers in the right placeOr realizing that a decorator would make the code so beautifulThis is where Python is really good. Small simple things improving flowNext is magic Overriding __getattr__() goes here.Using metaclasses is probably in here as well.Python actually encourages you with it’s dynamical propertiesIs it always maintainable? No.CleverNot a good placeI have some real-world examples