8 ms·
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 l
by skylan_q 15y ago
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?
- tdfx 15y agoLets you target the JVM without writing Java, among other things.
- rglullis 15y agocough http://www.jython.org/ http://www.jython.org/ cough
- tdfx 15y agoThis occurred to me after I finished writing that post.
- skylan_q 15y agoYea... 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.
- rayiner 15y agoI 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.
- jkkramer 15y agoIn 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 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 http://web.mac.com/ben_moseley/frp/paper-v1_01.pdf Simple Made Easy: http://www.infoq.com/presentations/Simple-Made-Easy http://www.infoq.com/presentations/Simple-Made-Easy
- icandoitbetter 15y agoYou actually get better code density with Clojure, for large enough programs. And a WAY better code density when you try to do multithreading.
- omlette 15y agowhat 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.
- spacemanaki 15y agoThe big differences between Clojure and Python are probably twofold: it's a Lisp, and it focuses on getting concurrency right. We've had Lisps for a while, and Python only really lacks Lisp macros, so let's think about the concurrency stuff... Clojure's design goals combine some deep ideas about identity, state and time together and includes data structures and a concurrency API that supports these goals. It's going to be hard for anyone to just convince you in a comment like this, and even if they could, I'm not the one to do it as I'm a Clojure noob. You should read this essay http://clojure.org/state http://clojure.org/state and watch this talk http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hic.... I think you will find that Clojure is pretty interesting, even if you don't start using it right away. I apologize for just throwing you links, but I can't do it justice, and Rich Hickey is a great lecturer, so you'll get more from his stuff.
- dkersten 15y agogetting better code density/more productivity Its not so much about brevity or productivity as it is about correctness. Functional programming and immutable data makes it easier to reason about code and to prevent bugs/errors, especially in the context of concurrent/multicore code.
- moonboots 15y agoUnfortunately, Jython is at 2.5.2, 3.5 years behind cpython.
- rglullis 15y agoThat 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.
- bretthoerner 15y agoWhile I'd agree Python 2.5 to 2.7 doesn't bring a swath of language features with it... it's a good sign of Jython's slowing/sluggish growth/development. Personally, I want to use a language implementation that will be around and (well!) supported for many years.
- vorg 15y agoNone of you three mentioned Python 3.0 to 3.2.
- bretthoerner 15y agoThat's because they don't matter to anyone.
- vorg 15y agoIt seems common that people don't upgrade to a breaking version of a programming language based on name or distro channel alone. Hence the slow uptake of Python 3 and Perl 6.
- Luyt 15y agoHow does Clojure's Java interop compare to Jython's?
- omlette 15y agoclojure'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.
- lucian1900 15y agoIn some ways it's nicer (clojure fns are java Callables), in some ways it's less nice (harder to extend a class).
- deleted 15y ago[deleted]
- calebmpeterson 15y agoClojure has no GIL and the concurrency API has few rivals
- skylan_q 15y agoGood point. Thank you for this.
- dkersten 15y agoClojure has excellent concurrency support. Clojure has a focus on functional programming, immutable data[1] and the sequence abstraction[2]. Clojure is a Lisp and has most[3] of the super-powerful metaprogramming facilities that you would expect from a Lisp. This means you can, with enough effort, mold the language to suit your needs, even turning it into a completely different language should you wish to do so. Clojure is not object oriented, though it does allow you to instantiate and create Java objects for the purpose of interacting with Java libraries. Clojure does support OO-like code through its Records/Protocol system. Clojure has out-of-the-box support for multimethods. Clojure runs on the JVM and therefore has access to the many many libraries written in Java or other JVM languages. Pure Clojure code is, as far as I can tell, higher performance than pure CPython code. PS: Just for the record, I love Python and use it a lot (and have actually been out of touch with Clojure for almost nine months now, sadly). The above are reasons why you may want to learn Clojure - not reasons to drop Python. [1] The benefits on pure-functional code and immutable data are that it makes concurrency easier and safer and that it makes code easier to reason about as you do not need to consider that 1) side-effects are happening behind your back and 2) the data is being changed elsewhere (which is also why it makes concurrency easier). [2] Similar idea to Pythons iterables, except IMHO Clojure's sequences are much more a part of the core language than iterables in Python, in that in Clojure most things are sequences, while in Python this isn't the case (though a lot of things are iterables). [3] I say most because Clojure does not have reader macros
- zurn 15y ago"Pure Clojure code is, as far as I can tell, higher performance than pure CPython code." Not so here; the author mentions that the Python version is faster (in his blog post).
- AlexBaranosky 15y agoAdding type hints to the relevant spots in the Clojure code might have helped him in terms of performance.
- schiptsov 15y agoClojure is NOT a Lisp at all. It lacks one of the most essential abilities of original Lisp - recursive function definition. Stop repeating things you don't know.^_^
- sbochins 15y agoThis post has been on Hacker News multiple times. It usually comes up on the weekend when people post a lot of Clojure stuff. If you read the article, it says that the Clojure implementation was meant to mirror Norvig's Python implementation. The clojure code could certainly be written more succinctly. I thing there was another article that did this. Would have to look it up though.
- cop359 15y agoFollow up question. How does it compare with Scala?
- iso8859-1 15y agoThis was just discussed on Reddit: http://www.reddit.com/r/Clojure/comments/mhg7c/sell_clojure_to_me/ http://www.reddit.com/r/Clojure/comments/mhg7c/sell_clojure_...