Live data from Hacker News

Clojure & Python, Side by Side

tin.nu

11–20 of 67 posts

Re: Clojure & Python, Side by Side

#11
post #4

This is pretty cool. I know python well enough to hack my way around it. I'm probably missing something, but now I have to ask: what would be the point in me learning clojure?

Clojure has no GIL and the concurrency API has few rivals

Good point. Thank you for this.

Re: Clojure & Python, Side by Side

#13
This is really neat. Although, one thing that makes it easier to map this program from Python to Clojure is that the original program was written in a pretty functional style. It would be interesting to see if a more imperative sample program, or one using more object-oriented features, would map similarly.

Re: Clojure & Python, Side by Side

#14
post #6

Earlier quoted context omitted.

cough http://www.jython.org/ cough

Unfortunately, Jython is at 2.5.2, 3.5 years behind cpython.

That is certainly a problem. But there are very few language constructs in Python >= 2.6 that are missing in Python 2.5, and the really missing features (e.g, multiprocessing module) have better alternatives in the JVM, or are redundant. You lose some portability, but Jython 2.5 doesn't seem to be that limited in capabilities.

Anyways, YMMV. All I got to do once was set my Django application to run on Jython, and that was relatively painless.

Re: Clojure & Python, Side by Side

#15
post #7

Earlier quoted context omitted.

This occurred to me after I finished writing that post.

Yea... I'm still confused as to the whole point of pure/near-pure functional programming if we're not getting better code density/more productivity against other languages which I (and some others) find easier to work with. I guess all I'm saying is "convince me!" :) I'm all ears.

I mean the answer is that the Python example is nearly purely functional to begin with. It uses list comprehensions heavily and I couldn't find any mutating assignments in a quick glance of the code. Which is not surprising, since it was written by Peter Norvig, who wrote a very popular Lisp book.

I think what Clojure can offer on top of that is macros, the advantages of which are really only evident on bigger or harder problems.

Re: Clojure & Python, Side by Side

#16
post #7

Earlier quoted context omitted.

This occurred to me after I finished writing that post.

Yea... I'm still confused as to the whole point of pure/near-pure functional programming if we're not getting better code density/more productivity against other languages which I (and some others) find easier to work with. I guess all I'm saying is "convince me!" :) I'm all ears.

In short: FP makes programs easier to reason about and understand by using trustworthy abstractions. Here are some resources to check out, which explain better than I could:

Why Functional Programming Matters: http://www.cs.utexas.edu/~shmat/courses/cs345/whyfp.pdf

Out of the Tar Pit: http://web.mac.com/ben_moseley/frp/paper-v1_01.pdf

Simple Made Easy: http://www.infoq.com/presentations/Simple-Made-Easy

Re: Clojure & Python, Side by Side

#18
post #7

Earlier quoted context omitted.

This occurred to me after I finished writing that post.

Yea... I'm still confused as to the whole point of pure/near-pure functional programming if we're not getting better code density/more productivity against other languages which I (and some others) find easier to work with. I guess all I'm saying is "convince me!" :) I'm all ears.

You actually get better code density with Clojure, for large enough programs. And a WAY better code density when you try to do multithreading.

Re: Clojure & Python, Side by Side

#19
post #12
post #6

Earlier quoted context omitted.

cough http://www.jython.org/ cough

How does Clojure's Java interop compare to Jython's?

clojure's interop is perfect and i have never had any problems. if the library is bad then you can just wrap it in clojure and put a custom api on top of theirs but ive only had to do that once and it was a groovy library.

Re: Clojure & Python, Side by Side

#20
post #7

Earlier quoted context omitted.

This occurred to me after I finished writing that post.

Yea... I'm still confused as to the whole point of pure/near-pure functional programming if we're not getting better code density/more productivity against other languages which I (and some others) find easier to work with. I guess all I'm saying is "convince me!" :) I'm all ears.

what converted me was having to do highly stateful, real time statistical models. you have data coming in from multiple sources and you have to do lots of computation on them. if you don't have persistent data structures then it becomes so easy for the program to use data from the future or excised noise and your results will just be completely wrong and it's very hard to find the source of error.

if youve never done FP, then it does feel really weird. but once you are used to it, so many things become much easier.

Post reply on HN