279 points · by jrheard · 13y ago · 108 comments
So I put off learning Clojure for about a year or so. However, I grew more and more weary of Java's obvious shortcomings, the inherent bureaucratic nature of the language and lack of modern programming features (such was the situation at the time at least, things are starting to look better for Java nowadays) and started to look to other languages. I tried Scala. It didn't work out. I still wanted to leverage my existing knowledge of JVM and the whole Java ecosystem, so I turned to Clojure again. Also, having spent perhaps too much time on HN, I really wanted to see what that fuss about Lisp was all about.
Anyway, what I found out was that you do not, in fact, need to be a genius developer to learn Clojure. Actually, Clojure was everything I hoped for. It's dead simple. The syntax is minimal compared to some other languages. You may have heard other people say that learning Lisp can be an enlightening experience. Yes, there definitely are some enlightening moments, but not in the sense that you need to spend years meditating on something to be able to understand it. Read a good book, there are plenty of those around now, watch some of Hickey's talks, and you'll get it.
To summarize, here's my message to anybody who is thinking of learning Clojure - don't get discouraged and give up on Clojure before even trying to learn it just because it's a Lisp. It may seem strange and perhaps a little frightening at first, but once you spend some time with it, you'll get amazed at how wonderfully simple it really is, and how powerful it is precisely because of this simplicity.
See? The magic was within you all along.
:)
I wonder if the causation is confused, here. That is, you do not need to be a top percentile programmer to understand or use Lisp. You are -- or become -- a top percentile programmer because you've learned Lisp.
I don't know if the relationship is as direct as all that. But I do think that if you learn and internalize some of the lessons of Lisp, it will expose you to new ways of thinking about programming as well a programming problems, and this is correlated with being a good programmer.
One particular example: the close relationship between code and data in Lisp pulls aside the curtain a bit on some concepts which are more obscured in languages like Java or C++.
For one, recursion. I 'got' it as far as the fact it's a function calling itself but it was only through digesting Lisp books, writing lisp and talking about Lisp that I finally got it. SICP helped further with recursive-iterative stuff too - it doesn't just need to call itself to be recursive.
Another is functional programming.
There are many more but the point is that I could have learned all these concepts, mentioned or not, in other languages but it was the simplicity of Lisp that I feel allowed me to truly understand them. I also feel if I dedicated more time into Lisp, I'd get much more than just a new language out of it.
One thing though, regarding this page, is that you don't need to install clojure with brew. Leiningen takes care of all that... clojure is just a jar that's included in your project, aka a dependency, and Leiningen manages that. This lets you tie a specific version of clojure to that project, which is handy for some legacy projects that aren't maintained anymore.
Also, if you drop the brew references, then this becomes OS agnostic. Just go to the leiningen page on github[1] and it'll get you started: osx, windows, linux.
I develop with clojure on my mac and I've not brewed anything related to clojure.
You do not "install" clojure. You depend on clojure just like you might log4j or joda-time
Also, I don't think anything would preclude non jvm hosted languages from doing something similar. I think it is a better solution than say virtualenv from python.
This is what rlwrap is for. Call `rlwrap clj` instead of `clj`, and you get all that and more (C-r, for reverse incremental search, etc). Works with every other REPL that doesn't bother to re-implement read-line.
As of a week or so ago, I started using Emacs with Clojure & nrepl. Aside from the occasional teething problems (still not used to the Emacs paradigm), it's amazing. Merely having the REPL in a text-editor-like buffer is a big win, and there's a bunch more that I'm still incorporating into my workflow.
But rlwrap is still a very useful tool because it works with every REPL. It will always be there, for those first sessions when you start learning a new language, or when you just need to answer some question about a language you rarely use, or when you write your own interpreter and don't want to also write read-line or an Emacs inferior-foo-mode.
I also recommend the Value of Values video presentation: http://www.infoq.com/presentations/Value-Values. It will help you internalize Clojure's approach to data.
I really wish I could remember why I didn't experience nearly as much pain starting out as the author, but I'm glad that he took the trouble to put this together.
The one I did bite the bullet on and watch in full was his talk on “hammock-driven development”. I liked it, but couldn't help feeling it would have made a very nice blog post that I could've read in 5 to 10 minutes as opposed to watching a 30 minute video.
I second fogus' comment about the Joy of Clojure, as well. I started with Simple Made Easy and the Value of Values before I even jumped into Clojure, and the Joy of Clojure dovetails quite nicely with all of the above.
I've always wished, though, that all "getting started" guides would just provide a chef recipe or machine image with everything ready to go. Getting to know a language shouldn't require jumping through an hour of hoops and documentation to get it set up.
(Of course, the guide here is broader than simply getting your system set up.)
It doesn't get much easier than pulling down the master `lein` script (or `lein.bat` for Windows) with wget/curl and setting it up on your PATH as an executable. This is similar to rvm[2], nvm[3], perlbrew[4], et al.
You'll need to have Java installed before proceeding to the next step.
Once you've done that, you can run `lein repl` in your shell -- Leiningen will bootstrap itself when it's run for the first time, and when it's done you'll be presented with a Clojure REPL. Now you're ready to start exploring and learning:
http://clojure.github.com/clojure/
Also, please join the friendly community in #clojure on irc.freenode.net[5]. You'll find folks in there nearly 24/7 who are willing to answer questions you may have as you learn your way around. The discussion group[6] is also a great resource.
[1] http://leiningen.org/#install
[2] https://rvm.io/
[3] https://github.com/creationix/nvm
For those of you in the industry, why would I want to use Clojure? What would be a good project to try it on? A Web app? Why is it worth learning it?
Over the past couple of years, I've learned Common Lisp by working through Conrad Barski's Land of Lisp[0] and dabbled in Haskell via Learn You A Haskell[1]. I had a great time learning both, but I found that Common Lisp had a decent number of warts (e.g. four different kinds of equality) that seemed to be primarily due to backwards-compatability concerns, and I had a really hard time getting up and running when trying to write a simple webapp in Haskell. In addition, I've gotten spoiled by how batteries-included Python (which I use at my day job) is; the library scene for both of those languages seemed lacking in comparison.
What I like about Clojure is that it gives me fast immutable data structures, has a really strong emphasis on functional programming, and has access to a really huge amount of useful libraries.
So - I've mainly been learning Clojure as a nice treat for myself; the amount of jobs that exist that employ programmers to code specifically in Clojure didn't even really occur to me as something worth thinking about. It's just really a lot of fun to program in. Also, with any luck, I'll be able to transfer any lessons I learn from Clojure to my daily work in Python.
(Haskell still has a very special place in my heart [I do frequently find myself wishing I had types], I'm not trying to dis Common Lisp nor Haskell, I'm just trying to honestly answer the question of why I thought it was worth learning Clojure).
If you really think that "four different kinds of equality" in Common Lisp is a wart, then I recommend that you read "The Best of Intentions" (http://www.nhplace.com/kent/PS/EQUAL.html) by Kent Pitman. The article explains why that situation is quite intentional, and why it is very rational, and why it is in fact ill-advised to expect a single meaning for "equal" ... or, in fact, other "obvious" concepts like "copy" ... to be sufficient.
That article was one of the many over the years that helped me refine the way I think about programming and programming languages.
When you say "has a huge amount of useful libraries" but then say that Python is "batteries included", which libraries in Clojure are particularly useful? Which ones did you wish it had?
2) I used those two phrases interchangeably - I consider both Clojure and Python as "batteries-included" languages. Case in point - before I was aware that Clojure Toolbox existed, I was able to google "clojure http request" and find several libraries that let me perform HTTP requests programmatically that I could include in my project.clj and start using right away. My memory's a little fuzzy, so apologies if this is completely wrong, but I don't recall having as easy a time doing that in e.g. Common Lisp or Haskell.
As far as which libraries in Clojure are particularly useful - Ring and Compojure are fantastic, and core.logic[0] is extremely interesting; I'll write a blog post showcasing core.logic (and using it for my first time ever) at some point. Midje is great for writing unit tests. I've only been using Clojure for a few months, so I can't point to too many others that have really been extremely useful for me, but I definitely recommend checking out the Clojure Toolbox[1] for a more thorough list of the main contenders.
[0] https://github.com/clojure/core.logic/wiki/A-Core.logic-Prim... [1] http://www.clojure-toolbox.com
If you want to start your own venture, using a powerful language like Clojure might give you an edge.
http://www.paulgraham.com/avg.html
Learning a powerful, less main stream language like Clojure can also signal to smart, innovative software companies you might be the kind of person they should hire.
From my _very_ short experience (I've started coding a simple game), here are my two cents:
- If your application is heavily dependent on state, which changes continuously and must be maintained during most of the execution time - like a game - it may not be a good fit. You'll waste a lot of working around the fact that each modification results on new objects. - If your application comprises mainly of short requests that may create some state that will most certainly be discarded shortly after - like a web application - then I think it's a good fit and you'll probably enjoy it better.
Once again, I've just got started with it, so take this with a grain of salt :)
I find the majority of my time in writing stateful programs goes towards reasoning about safety, and having access to STM lets me write correct code with less thinking. Then I focus on optimizing the parts where performance is critical.
I have found that this rarely enters discussions regarding Clojure, although the STM is frequently lauded. GHC's STM also does not work with the IOMonad, which is clear because of the types, and is articulated in books such as such as Real World Haskell.
http://book.realworldhaskell.org/read/software-transactional...
Are people really getting benefits from transactions which do not involve I/O?
Of course, everyone there is doing FP in C++.
I may try the blog/webapp idea with Clojure.
# make sure you have java/open-jdk already
wget https://raw.github.com/technomancy/leiningen/preview/bin/lein && chmod +x lein && ./lein replI also want to point out to those who are using Windows: Yeah, you could, but this is not a good idea. Leiningen 2 is not available for Windows, but you can still get quite a bit done. At some point, you just have to bite the bullet and install a VM with Linux to really dive into it.
Light Table has a windows client; Eclipse with the counterclockwise plugin (a leiningen/clojure plugin) runs great on windows; running from the command prompt works great on windows.
I agree though, that a "Learn Clojure The Hard Way" a la Shaw would be nice.
I'm not a huge fan of using a bunch of IDEs and just use Emacs. After a year of fighting with Windows, I got fed up with it and installed Linux with a VM and now everything works like a dream.
EDIT TO ADD: I would love to do a project like Learn Clojure the Hard Way, but I'm simply not confident in my abilities to do it correctly. I've written some pretty significant programs in Clojure (see my profile), but I wouldn't be able to solve but a few Project Eulers with it. I'm simply too new at programming in general.
I just used the batch file from the leiningen github to get up and running on windows.
Someone else brought up the point that lein needs wget or curl, and that isn't something that is installed by default on windows. I happened to already have them, so I never thought much about it.
GNU has a version of wget and maybe curl too for win32. And there is always cygwin if you like.
https://github.com/technomancy/leiningen http://gnuwin32.sourceforge.net/packages/wget.htm
I'm pretty much a novice when it comes to software in general, but I dip my toes in a lot of different languages. I don't think that would be a problem for LCtHW though... I mean, it could be a collaborative effort as a github page or wherever.
Get the framework in place, start with the basics, let the experts fill in the advanced stuff.
One of the things you can do when learning something new is to hop onto IRC and join a channel related to the topic. I almost always have got a good overview of things just by asking around what I am supposed to know.
I've read a page[1] listing differences between Clojure and other LISPs, but I'm not sure that I fully understand the implications of these differences.
this video by Chas Emerick (co-author of clojure programming) also gives a good introduction to start with clojure, especially for people who uses eclipse.
(:headers resp)
This construction is confusing - it breaks environmental model (scoping) and general evaluation rule of Lisps - is :headers a global symbol? a part of foo namespace? Is it macros? (resp :headers)
On the other hand, this form is perfectly consistent - I'm sending to some closure which is bound in a global or other environment a constant message.The assumption that the reader function implicitly transforms first form to second is of no good, because it is not obvious and breaks intuition about environments and violates principle of less astonishment.
That thing (:headers resp) returned - what language is it?)
It follows Clojure's evaluation rules just fine: it's an object that implements the IFn interface.
> On the other hand, this form is perfectly consistent - I'm sending to some closure which is bound in a global or other environment a constant message.
resp isn't a closure, it's a map, which is also an object that implements IFn.
(:keyword m)
calls in turn (get m :keyword)
That's just a basic feature of the language. No macros involved.