Upgrade to Pro — share decks privately, control downloads, hide ads and more …

On the persistence of bad ideas

rbanffy
April 25, 2012

On the persistence of bad ideas

A short collection of lessons on how you are not as smart as you think you are

rbanffy

April 25, 2012
Tweet

More Decks by rbanffy

Other Decks in Programming

Transcript

  1. 2 A student def palindrome(s): for i in range(len(s)//2): if

    s[i] != s[-(i+1)]: return False return True
  2. 5 A fan of lambdas def palindrome(s): return all(map(lambda t:

    t[0] == t[1], [ (s[i], s[-(i+1)]) for i in range(len(s)//2)]))
  3. 6 An Erlang (or Haskell) fan def palindrome(s): if len(s)

    <= 1: return True elif s[0] == s[-1]: return palindrome(s[1:-1]) else: return False
  4. 7 Someone in a hurry from concurrent.futures.thread import ThreadPoolExecutor def

    palindrome(s): with ThreadPoolExecutor(16) as executor: return all(executor.map( lambda t: t[0] == t[1], [ (s[i], s[-(i+1)]) for i in range(len(s)//2)]))
  5. 8 Someone in a hurry (who knows about the GIL)

    from concurrent.futures.process import ProcessPoolExecutor def equals(t): return t[0] == t[1] def palindrome(s): with ProcessPoolExecutor() as executor: return all(executor.map( equals, [ (s[i], s[-(i+1)]) for i in range(len(s)//2)]))
  6. 11 What we've just seen • student • pythonistas •

    lambda fans • functional • threadist • processist • poets
  7. 12 Analysis (worst case) 10 100 1000 10000 100000 1000000

    1.00E-06 1.00E-05 1.00E-04 1.00E-03 1.00E-02 1.00E-01 1.00E+00 student pythonista smarter pythonista lamda fan functional threadist processist poet counting poeta