Initial Thoughts on Clojure
acooke.org
acooke.org
I will say that the online documentation IS atrocious and basically impenetrable, and usable code samples are quite difficult to come by. That being said, it's a very young language, with a very active, helpful and -- dare I say -- friendly IRC channel. (And by the way, a couple of top-notch eval bots)
The documentation piece is easily overcome by spending $20 on an ebook. Joy of Clj and Practical Clj are both very readable & accessible. The code samples are clear and concise, and the explanatory prose is excellent.
IDE support... well, I use emacs. It's widely recommended people use emacs for Clojure simply because it is so well integrated with it. REPL and line evaluation are fantastic in emacs. People who don't like/want emacs tend to use vim's Clojure mode, at least according to IRC.
I will say that the main pain point I had in getting started with Clojure was building the environment. The "best practices" for a Clojure environment has shifted wildly, as far as I can tell, over the past few years, so most/many of the blog posts that describe how to get it set up are wrong, or very dated and unsupported by current software (e.g. Leiningen).
All in all if you are interested in learning Clojure, you are doing yourself an enormous disservice by not joining #clojure and asking your questions there.
i do use emacs for text editing, so i'll try it for clojure (i should say that there was only one wrinkle in getting the environment working in intellij - that was adding clojure.jar to the classpath, which it told me to do in an error popup, so it wasn't hard at all).
ps to save others googling: http://joyofclojure.com/ ; http://www.apress.com/9781430272311
Tutorials
http://github.com/relevance/labrepl (gives a kick in terms of functional thinking, use of higher order functions etc)
https://github.com/functional-koans/clojure-koans
Documentation
http://en.wikibooks.org/wiki/Clojure_Programming
http://www.clojureatlas.com/ (Finding functions by browsing the relations of APIs and API-functions is just to nice)
http://cemerick.com/2011/07/05/flowchart-for-choosing-the-ri...
http://www.clojure-toolbox.com/ (not up-to-date)
I'm sure i missed something, but those links can really be helpful.
I admit that the complaints about the lack of examples in the documentation does confuse me a bit. The documentation sites for C and C++ don't seem to include examples either. For me, tutorials and books were always the go to places for examples. I will agree whole heartedly that some of the 3rd party libraries like ring/compojure need some serious documentation improvement, in particular since the architecture of these libraries is fairly complicated.
Could someone link examples of good documentation they like from other languages to help clarify?
Another example of documentation that has served me well is the numpy+scipy+matplotlib combo:
Making C/C++ documentation the standard for documentation is like making a Chevy Nova the standard for features in modern automobiles.
Maybe it's just me, but I find the documentation to be very good. Everything on clojure.org is relevant, clear and concise. I read two books too, but I learned the most from clojure.org.
> The documentation is bad.
Mostly true. Initially, I got The Joy of Clojure, which is really good and helped me bootstrap my learning process. Now, if I need to know something, I look up the source. This process seems to work well.
The only problem with this strategy is that sometimes I'll not know of a better way to solve a problem (for example, I only discovered update-in a few days ago. Don't ask what I've been doing before that.)
The best way to solve this problem is by pair programming with someone else who knows Clojure. Failing that, you can hop on IRC; people there are super helpful and willing to write big code samples just to make sure you get it. And be sure to read a lot of source code to pick up common idioms, etc.
> Error messages are unhelpful.
This is true, but here's a quick tip: if you just look for errors that come from your-namespace.core (or whatever) then you can rapidly ignore about 99% of the extraneous junk that pops up.
Unfortunately, there's always that 1/10 chance that your error has no line number. Not much you can do about that, except guess where the reported error is coming frm, and hope for more progress in clojure in clojure :/
> IDE support
Use emacs with swank clojure. Just do it. It's amazing, and you won't look back. I'm saying this as a hardcore vim user with visual mode tattooed on his back. (I have to use viper-mode and vimpulse - which makes emacs pretty much just the same as vim.)
> It suffers from using the JVM
I really don't understand this point. I believe JVM integration is a win all around. It allows for speed without much effort, and it gives access to a huge wealth of libraries without need for a community to build them.
Some closing remarks:
You've got to remember that Clojure is only 3 or 4 years old. If you're (subconsciously or not) comparing it to languages with 10 or 20 years of history, the older languages will always dominate in terms of documentation, support, etc. This is unfortunate for new languages, but also exciting, because it means that even beginners like me and you can pick off low hanging fruit and make important contributions.
I ran some tests with a function that did nothing but recur/drop on a sequence. There was no speed difference between a vector, a LazySeq (previously evaluated), a PersistentVector and a PersistentList with a million elements. I tried it with ten million and it was 400 times slower with both a LazySeq and a PersistentVector. Attempting to make a PersistentList from the 10M element LazySeq with 'into' resulted in running out of heap space. I did not try again with more heap space allocated.
but i agree it's not a "deep" analysis. did you miss the part where i said i had only used the language for a day? or the word "initial" in the title?
[edit:] actually, there is one more thing i want to say. one thing that has discouraged me from looking at clojure earlier is the agressiveness i've seen from the language's fanboys. fwiw.
I'd call Clojure's use of the JVM a win, not a liability.
And - I'd like to see if I can (ab)use those languages to improve my experiences with Android.
So far I'm heavily leaning towards Scala. The documentation seems to make more sense to me. It seems powerful to ~no end~. This post now, while being not totally impressed about all things Clojure, ends with an unqualified 'still more usable than Scala', which threw me off.
More data points, please? If the writer is true and makes sense: What's the reason for this comment? Convert me. :)
* Clojure is strongly and dynamically typed. Scala has a complex type system, which from what I understand many Scala developers don't fully understand or utilize it. Clojure doesn't suffer much in performance, however, because you can sprinkle in type hints for performance after the fact wherever it turns out to be necessary.
* Clojure is a Lisp. The benefits of that are a whole other discussion, but homoiconicity and macros are undoubtedly pretty cool.
* Scala is multi-paradigm, Clojure is unabashedly single-paradigm.
* Scala includes the kitchen sink, Clojure is highly opinionated about what it provides. As Brian Hurt says, "It's not what a programming language makes possible, it's what it makes easy." For one example, you can do immutability in Scala, but you're also free to go in and make a hairball of state if you want. Clojure has decided immutability is good, and forces you to manage state in a controlled way.
* Clojure is less complex (in the sense Stu Halloway uses the word in his talk on Simplicity, http://blip.tv/clojure/stuart-halloway-simplicity-ain-t-easy...)
Full disclosure: I'm a huge Clojure fan and author of Practical Clojure, and haven't used Scala on any nontrivial projects, so I'm probably somewhat biased.
"When we say that a language is expressive, we mean that it is easy to use. When we say that a type system is expressive, we mean that it isn't."
- Gilad Bracha
However, my money is on neither. I'm looking forward to Kotlin from Jetbrains: http://confluence.jetbrains.net/display/Kotlin/Welcome
At this point, I have written significant amounts of code in both languages, and I honestly prefer Clojure. Scala is definitely a big step up from Java, and there is a lot to like in the language. Nonetheless, I think that Clojure is a step up from Scala.
There have been a number of times when writing in Scala that I wish I had some of the features of Clojure, macros in particular. Scala provides many neat features that would be implemented as macros in Clojure, but there are some things that can be done as macros that cannot be done in Scala.
Of course, typing is a big issue. I'll have to admit that when writing client code static typing is very nice, but when writing library code dynamic typing makes things easier. Most importantly, Scala suffers from some of the typing problems that are part of the JVM, most notably: type erasure in generics. Scala provides some means to reify generic types, but it is still a pain to work with. I think that Clojure also contains superior polymorphic dispatch capabilities.
In the end, they are both fine languages. I enjoy coding in Scala and Clojure more than C++ or Java. Still, if I have the choice between the two, I'd go for Clojure.
I think I've narrowed my next learning project down to either clojure or node. Node seems perhaps more immediately useful and easier to grok, while clojure may offer more for my overall development as a programmer. I'm not the type to build a throwaway educational app--I have to feel like whatever I'm working on could turn into something real, even if it's unlikely, so if I were to go with clojure, I'd want it to be for its potential to really offer more power and productivity in making something cool and getting it launched, not just as an academic exercise. I have a couple busy months of contract work to go before I'll be able to dive into anything, so it's great to read reports like this while the decision stews.
For that matter, you might not want Clojure to be your first lisp experience. Have you considered Racket, the scheme dialect? It seems to have lots of useful libraries, in addition to being, I don't know if "cleaner" is the right word, but something like that. A bit more traditional, maybe simpler.
I don't have that much experience with lisp or Node. If someone with more experience can correct my impressions, I would be grateful.
Pros: 1. Easier to setup (with a single script from https://github.com/technomancy/leiningen) 2. Benefits of a lisp-1, with nicer syntax (fewer confusing parens) 3. Easier to get started with Emacs + swank-clojure + lein 4. Wealth of Java libraries 5. Functional
Cons: 1. Can't think of any, unless you want Interface Builder and similar, or are desperate to program using call/cc or are in any of the above ways a non-beginner. drscheme is a nice counterpoint though, in that the learning enviroment could include a bit more hand-holding.
IMHO for those coming from ruby/python etc. Clojure is a huge win. With square brackets for function-args, if you turn off or dim parens (emacs has several options such as rainbow-parens) the source looks very much like python.
And with M-q and friends and sexp editing, it behaves better.
The entries have been made every few hours. The author started to have some hopes about Clojure, then in the same day (heck! in three hours) he resigned.
Even geniuses need some time to digest information. The best way to do it is to think hard during a day, relax and let the brain work on it during sleep. You're lucky if some insight comes just another day. But it will come eventually.
I'm telling this not in the defense of Closure, but in the defense of a proper method of examining the world around.
And if you like modern Lisps, you can always check Racket. (But slowly :)
Intellij's La Clojure does a little more than syntax highlight: minimal refactoring support, rainbow parenthesis, smart parenthesis, syntax highlighted repl, great autocomplete support, awesome code navigation, autocomplete for java classes and live templates.
Not to mention that slurp forwards (Edit->Clojure->Slurp Forwards) is really nice. Example. Place your carret on |
(println|) (reduce + [1 2 3])
Slurp forwards will turn it into (println (reduce + [1 2 3]))1. While the complaints about error stack traces and documentation are valid, I would personally use a language for a month or two before publicly publicly criticizing it.
2. If you want to learn Clojure and/or Scala, I think that it is worth taking an initial detour and learn a little Haskell. Every time I spend a few evenings studying Haskell I feel like I understand Clojure and Scala a bit better.
3. I think that tool support is very good. I must admit mostly using IntelliJ with the Clojure plugin, but I also use Emacs+Slime for several hours a week.
4. There are many awesome projects and frameworks written in Clojure - to me this is the clearest indication that Clojure is an important language and deserves careful consideration for new projects.
TL;DR: it's an excellent language, but it's dynamically-typed and that can be a pain.
The language itself is pretty simple. The default collection type is a lazy seq, and that takes a little bit of getting used to, but it's actually a great thing. It allows you to compose filters, maps, et al without taking a hit to performance on account of needless copying.
The language's documentation is mediocre, true, but that doesn't matter that much given that learning a new language is a 6-month (at least) investment. Trust me: if you've never used a functional programming language before, it's more than worth your time.
Some of the error messages are useless, mainly because of Java hangover. Clojure is a very pretty and powerful language built on top of an incredibly ugly one. Impedance mismatches are hardly surprising. Again, this is something that takes a few months to get a hang of, but once you've got a handle on it, it isn't so bad. Clojure is amenable to tracing/printf style debugging, which isn't so bad if you structure your code in an intelligent way. Since the language is mostly functional, the path of least resistance usually is intelligent structuring.
Clojure is a great choice if you're disciplined and willing to do, if not full-on TDD, development with a lot of testing involved. You have to unit test; fast-and-sloppy development will cripple you. It's dynamically typed, and I'll probably always prefer static, but if we accept that the static-vs.-dynamic debate remains unresolved (a lot of smart people with great arguments on both sides) I'd have to give it very high marks within the dynamic category. My ideal language would still be a statically-typed one, but Clojure is more than good enough in practice.
It would, by the way, be nice to get rid of some of all those self-promoting posts. New rule: You can not link to your own shit. Thank you, Sir.
also, a new account just to takes shots at me? did i shoot your dog or something?