9 ms·
Evolution of a Python programmer
- yan 17y agoThe web designer and windows programmer snippets are brilliant.
- cabalamat 17y agoThe enterprise programmer one is pretty good too. Reminds me of EJB (shudder).
- pwhelan 17y agoProductivity can only be measured by lines of code-- what a co-worker told me. Reminds me of that dark, evil place.
- yan 17y agoLikewise, productivity of surgeons can only be measured in numbers of stitches.
- drawkbox 17y agoGotta get that LOC count up.
- rubinelli 17y agoI don't know, it doesn't look flexible enough. The classes should be wired up at runtime using an XML config file. I also think it could also split the problem using a pool of threads to achieve better performance. Even better, you could queue up all the factors in a master node and have N slaves pulling from it and multiplying. After the queue is empty, all the master has to do is query each slave and multiply the intermediate results together.
- sophacles 17y agoI was a big fan of the: lazy python programmer, lazier python programmer, and python expert programmer series. Having been through that series, and watched many others go through it themselves, I find it to be the best HAHA-only-serious bit in there. I'm not sure what it is, but at some point every pythonista seems to go through this love affair with functools + itertols + roll your own haskellish modules.
- dkersten 17y agoIt would seem that the better you get at python, the more you really want a functional language. I know I went through this too (and I have moved onto functional languages for personal projects since..)
- sophacles 17y agoI remember that the "Real World Haskell" was one of the first books sold-out at the OReilly booth at Pycon 2009, if you want more supporting (anecdotal) evidence.
- Deestan 17y agoTo add to the evidence, I'm an experienced Python programmer who is currently waiting very impatiently for his Amazon shipment of "Real World Haskell" and "Purely Functional Data Structures". (Oh, and "Garfield Minus Garfield".)
- silentbicycle 17y agoWhile you're waiting for PFDS, here's Okasaki's thesis (http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf). It's the seed of the book.
- gtani 17y agoThere's sort of an emerging Big 4 (plus 1) of FP http://book.realworldhaskell.org/ http://book.realworldhaskell.org/ http://programming-scala.labs.oreilly.com/ http://programming-scala.labs.oreilly.com/ http://caml.inria.fr/pub/docs/oreilly-book/ http://caml.inria.fr/pub/docs/oreilly-book/ http://www.freetechbooks.com/introduction-to-objective-caml-t698.html http://www.freetechbooks.com/introduction-to-objective-caml-... don't know of any freely available content books on Clojure or Erlang;
- og1 17y agoI had to google the windows one just to make sure it wasn't real.
- AndrewO 17y agoDoesn't PEP 20 say that there should be only one way to do it? :-)
- sophacles 17y agoI know your question is a joke, but it is frequently asked in seriousness, so: No. Not at this granularity. Otherwise the python community would still be using plone, and Django would not exist. Or there would be only blocking (or non-blocking) io. And so on.
- brehaut 17y ago;; python programmer who reads HN and Proggit (defn factorial [n] (reduce * (range 1 (inc n))))
- Torn 17y ago;; Any programmer reading HN long enough to experiment with some lisp / clojure ;) (defn factorial [n] (apply * (range 1 (+ n 1))))
- brehaut 17y agoI was torn between those two formulations, but decided on the reduce because the academic purity of an implicit hylomorphism ;) However, your formulation is more idiomatic of a lispy solution.
- mrshoe 17y agoI'm proud to be a Lazy Python Programmer... but not lazy enough to skip "What's New in Python 2.5": def factorial(x): return x * factorial(x-1) if x > 1 else 1
- deleted 17y ago[deleted]
- notaddicted 17y ago# "close enough" programmer import math def fact(x): math.sqrt(2*math.pi*n) * math.pow(n/math.e, n) print fact(6) # lazy-er programmer def fact(x): factorials = {6:720} # found on my calculator, add more as they come up if factorials.has_key(x): return factorials[x] else: raise NotImplementedError print fact(6)
- Vivtek 17y agoNotImplementedError - that kills me!
- ajross 17y agoThe "first year pascal" example has a metasyntax error. It's missing a "#end" token for symmetry with the C example.
- alxv 17y agoFunctional programmer: import operator def factorial(n): return reduce(operator.mul, xrange(1, n+1), 1) print factorial(6) Cutting-edge programmer: import math print(math.factorial(6))
- shabda 17y agohttp://dis.4chan.org/read/prog/1180084983/ http://dis.4chan.org/read/prog/1180084983/ http://www.hackerne.ws/item?id=1012877 http://www.hackerne.ws/item?id=1012877 Wow the domain can make a huge difference. :)
- sriramk 17y agoI'm ashamed to admit that I actually learnt something new from this (the @tailcall thing)
- pmiller2 17y agoYou should never be ashamed to admit ignorance, especially after it's been cured. :-)
- pgbovine 17y agowait, is @tailcall part of the Python standard library? or just something the author made-up for illustrative purposes?
- notaddicted 17y agoI just tried typing it into the interpreter in 2.6 and 3, it doesn't appear to exist.
- bdr 17y agomade up http://neopythonic.blogspot.com/2009/04/final-words-on-tail-calls.html http://neopythonic.blogspot.com/2009/04/final-words-on-tail-...
- sophacles 17y agoThere are a few /very/ hacky @tailcall decorators floating around the web. In some cases they actually speed things up some small amount. A year or two ago there was a bug furor over bytecode hacking -- such things were the result :)
- micheles 17y agoYou can find a version of tailcall in the Python cookbook or here: http://pypi.python.org/pypi/decorator#dealing-with-third-party-decorators http://pypi.python.org/pypi/decorator#dealing-with-third-par...
- sophacles 17y agoWeb 2.0 programmer: import urllib import json def fact(n): res = urllib.urlopen('http://math.org/factorial/?' + urllib.urlencode({'n':n, 'format':'json'})).read() return json.loads(res)['answer'] fact(6) Edit: for a "web scale systems guy" throw an @memcache_memoize in there :) Edit2: fixed a syntax error. Edit3: general cased it. thanks lolcraft!
- lolcraft 17y ago{'n':6, 'format':'json'} Shouldn't that be: {'n':n, 'format':'json'}
- sharkbrainguy 17y agowhy write such a general case, YAGNI
- sophacles 17y agoMore of a scotty principle type thing: when management comes by and wants to us to figure out combinations of 7 things, we can claim it will take 5 days, get it done in a 1 char fix, play games all week. Come monday morning's meeting, don't drink coffee before hand (to look tired), and claim that for a little extra work (and a looong weekend) you got it to work for combinations of ANY NUMBER of things! Worse that happens: you get credit for taking one for the team, best case: "take the week off, thanks for your heroics!"
- umjames 17y agoIf you happen to know of a place where you earnestly hear "take the week off, thanks for your heroics!", please don't be stingy with their URL. I'd be interested in working there.
- sophacles 17y agoUnfortunately most of the 'best-case' type things I mention are highly unrealistic. I'll let you know if I do hear something tho. :)
- gregcmartin 17y agoI am going to have to go with Lazier Python programmer
- codexon 17y agoThis is an uninspiring ripoff of the older original here: http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.... And here is one that is actually well done for Haskell. http://www.willamette.edu/~fruehr/haskell/evolution.html http://www.willamette.edu/~fruehr/haskell/evolution.html
- nailer 17y agoThe article is entirely new content updated to fit an existing idea. How is that a 'ripoff'?
- alrex021 17y agoJava programmer: class FactorialCommand(object): def set_num(self, num): self.__num = num def get_num(self): return self.__num def execute(self): result = 1 i = 2 while i <= self.get_num(): result = result * i i = i + 1 return result cmd = FactorialCommand() cmd.set_num(6) print cmd.execute()
- Confusion 17y agoI kind of miss an @memoized version
- Deestan 17y agoBored Python programmer: def fact(l): return sum(map(bool,reduce(lambda I,l:''.join([l for I in I]), ['+'+'+'*l for l in xrange(l)]))) assert fact(6)==720
- whyenot 17y agoI don't understand. What's wrong with the factorial function that comes with python? from math import factorial done.
- gcb 17y agohttp://www.willamette.edu/~fruehr/haskell/evolution.html http://www.willamette.edu/~fruehr/haskell/evolution.html for all the closet functional programmers around here :)
- hyperbovine 17y agoThat's the link I was looking for, I knew had seen this somewhere before. The Python one is entertaining, but the Haskell one is brilliant. "explicit type recursion with functors and catamorphisms", ha. I finally learned what a functor is a few days ago.
- deleted 17y ago[deleted]
- jchonphoenix 17y agoWonder what a mathematicians python looks like...
- deleted 17y ago[deleted]
- nick_maxwell 17y agohttp://news.ycombinator.com/item?id=1089936 http://news.ycombinator.com/item?id=1089936
- alec 17y agoWhere's the one where the Python programmer has to make something go fast and needs to write a C module?
- jerf 17y agoThat would be trickier than it looks. Run this in your python interpreter: reduce(lambda x, y: x * y, range(1, 100)) Replicating that in C is certainly possible but you're probably not going to do it quickly, unless you're already pretty deep into that sort of thing.
- deleted 17y ago[deleted]
- samdk 17y agoThe "I find a way to use list comprehensions for everything" Python programmer: def fact(n): return eval('*'.join([str(x+1) for x in xrange(n)] + ['1']))
- pmiller2 17y agoHere's a better one (taken from http://code.activestate.com/recipes/67668/#c7 http://code.activestate.com/recipes/67668/#c7 ): f= lambda n: [[[j for j in (j*i,)][0] for i in range(2,n+1)][-1] for j in (1,)][0]
- viraptor 17y ago"I've got a lot of memory" or "runtime is more importatant than initialisation" programmer fact = init_fact() ... res = fact[x]
- est 17y agoPython one-liner anyone? >>> reduce(int.__mul__, range(1,6)) 120
- jbyers 17y agoEnterprise programmer made me laugh. Especially after spending a few days buried in SAML.
- yason 17y agoHeh, this is quite even better than the "Evolution of a programmer".
- Flow 17y agoSo funny. The Windows one makes me wanna abandon computers altogether.
- Groxx 17y agoI think I'll have to contribute some J code (can anyone uglify Python this much?): (*$:@:<:)^:(1&<) 6 Finds the factorial recursively. J programmers are masochists. (From: http://rosettacode.org/wiki/Factorial_function#Recursive_11 http://rosettacode.org/wiki/Factorial_function#Recursive_11)