... To Clojure.
Rajesh, you were right!
As far as language
- A REPL for fast development
- Functional programming with immutable values which makes it easy to reason about concurrency
- Concurrent programming via software transactional memory
- A Lisp-1 dialect
- OOP benefits without OOP using runtime polymorphism
- Lots of modern libraries by being hosted on the JVM
- A vibrant community (my F# groups, by contrast, have had barely 2 messages in the past month)
This idea of lazy sequences is powerful, because you can do things like get the 10,001st prime number without blowing the stack:
You can just see the number-crunchy goodness, mixed in with Lispy functional precision.
As far as practicality, there is simply too much awesome stuff.
- The language itself is available on GitHub
- It has nice documentation to get you started quickly
- There are great learning resources: 4Clojure clojure-koans
- Nice examples of algorithms such as Quicksort using Clojure
- Easy translation from Practical Common Lisp
- A freely available killer IDE supporting Clojure with project building and GitHub support
- Simple to complex web application support to EC2, Heroku, Google App Engine and others
Here's a screenshot of IntelliJ with a typical Leiningen project open:
You can see the typical Leiningen project layout, with /src and /test folders and subfolders. First, we'll write a
The test is in C:\Projects\CDT\Newton\test\Newton.test\core.clj, and the :use [Newton.utilities] tells it to look in the file C:\Projects\CDT\Newton\src\Newton\utilities.clj for our function. Note the use of metadata ^{:utilities true} to mark this as a utilities test, which we'll use later for organization. Our test checks that our to-be-defined sum test sums correctly over both a list and a vector.
Now here's the contents of C:\Projects\CDT\Newton\src\Newton\utilities.clj:
Finally, Leiningen allows us to choose test selectors so that we can specify which tests we want to run via project.clj:
Now by running lein at a command prompt (to save startup time) we can pick our tests:
Note in the first case, we don't expect any tests to run (test! means fetch dependencies and then run tests) because our sole test has been marked as a :utility. In the second case, we tell it to run :utility and it does, telling us that our test passed. Success!
If our test had failed, clojure's test suite would give us good information. Here, I'm going to modify the second assertion to fail. Watch what happens:
How cool is that?
I've so far read Clojure in Action and The Joy of Clojure (both highly recommended), plus enough daily doses to actually stop mucking about and start with the CDT code already.
So, a modern Lisp with powerful IDEs, modern libraries from the JVM, interactive REPL/TDD, great documentation, learning resources, and books -- what's not to like?



No comments:
Post a Comment