Tag: fp

One of the services my current team maintains was written in Clojure. Being a big fan of meetups, user groups, conferences, and brown-bag lunches, I have had the occasion to read some Clojure code in the past and write some hello worlds.

Given today we have this project, it is certainly a good time to learn Clojure for real!

I started then doing some research about Clojure, mainly about things one needs to know to get started. I turned some questions I’ve asked myself into a FAQ, which I’m publishing here mainly for self reference. If my initial research ends up helping someone else as a side effect, even better 😀

If you think something is not quite accurate or something really important is missing, let me know in the comments.

What are the language’s fundamentals?

Does it have a build automation system?

Leiningen is for the Clojure ecosystem what Maven and Gradle are for Java. It helps developers to scaffold new projects, resolve dependencies, run tests, etc. Leiningen has a command line interface called lein.

$ lein help
Leiningen is a tool for working with Clojure projects.
Several tasks are available:
change Rewrite project.clj by applying a function.
check Check syntax and warn on reflection.
classpath Print the classpath of the current project.
clean Remove all files from project's target-path.
compile Compile Clojure source into .class files.
deploy Build and deploy jar to remote repository.
# ...and many other tasks

Most Leiningen tasks apply in the context of a project. A project is a directory containing all the resources of an application, like source files, scripts, etc. The project’s metadata is stored in a file called project.clj, which lives in the project’s root directory.

Where can I find documentation?

clojure.org regroups a bunch of useful resources about Clojure. This particular link is very useful during development, since it describes vars, types, macros and functions by namespace.

There’s also the popular ClojureDocs. ClojureDocs is a community driven website where you can find documentation and examples.

How do I write tests in Clojure?

Clojure has its own unit testing library clojure.test. It is somehow limited IMHO, but it does the job.

There’s another library called Midje, which, from what I’ve understood, it’s quite popular within the Clojure community. Midje aims to provide a more flexible and readable style of testing compared to clojure.test.