Book Image

Clojure for Java Developers

Book Image

Clojure for Java Developers

Overview of this book

We have reached a point where machines are not getting much faster, software projects need to be delivered quickly, and high quality in software is more demanding as ever. We need to explore new ways of writing software that helps achieve those goals. Clojure offers a new possibility of writing high quality, multi-core software faster than ever, without having to leave your current platform. Clojure for Java developers aims at unleashing the true potential of the Clojure language to use it in your projects. The book begins with the installation and setup of the Clojure environment before moving on to explore the language in-depth. Get acquainted with its various features such as functional programming, concurrency, etc. with the help of example projects. Additionally, you will also, learn how the tooling works, and how it interacts with the Java environment. By the end of this book, you will have a firm grip on Clojure and its features, and use them effectively to write more robust programs.
Table of Contents (14 chapters)
Clojure for Java Developers
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using Cursive Clojure


Java already has some great tools to help us be more productive and write higher quality code and we don't need to forget about those tools. There are several plugins for Clojure depending on what your IDE is. Have a look at them from the following table:

IDE

Plugins

IntelliJ

Cursive Clojure, La Clojure

NetBeans

NetBeans Clojure (works with NetBeans 7.4)

Eclipse

CounterClockwise

Emacs

Cider

VIM

vim-fireplace, vim-leiningen

A lot of people writing real Clojure code use Emacs and I actually like using vim as my main development tool, but don't worry, our main IDE will be IntelliJ + Cursive Clojure throughout the book.

Installing Cursive Clojure

You can check the full documentation for Cursive at their website (https://cursiveclojure.com/), it is still under development but it is quite stable and a great aid when writing Clojure code.

We are going to use the latest IntelliJ Community Edition release, which at the time of this writing is version 14.

You can download IntelliJ from here https://www.jetbrains.com/idea/download/.

Installing Cursive Clojure is very simple, you need to add a repository for IntelliJ. You'll find the instructions to your specific IntelliJ version here: https://cursiveclojure.com/userguide/.

After you have installed Cursive Clojure, we are ready to go.

Now, we are ready to import our getting started project into Cursive Clojure.

Note

Cursive Clojure doesn't currently have support to create Leiningen projects from within the IDE; however, support is great in order to import them.

Here is how you will do it:

  1. Click on File.

  2. Import project.

  3. Look for your project.

  4. Open the folder or the project.clj file.

  5. Follow the Next steps in the IDE.

Now, we are ready to go, you can use the Cursive Clojure as your main development tool. There are a few more things to do with your IDE but I recommend you to look for them; they are important and will come in handy:

  • To know how to execute the project

  • To know how to execute the tests

  • To open an REPL connected to some project.

  • The key binding to execute some given piece of code (run form before cursor in REPL)

  • The key binding to execute a given file (load file in REPL)

One important part of Clojure programming is that it can modify and reevaluate code in runtime. Check the manual of your current version of Clojure and check for the structural editing section (https://cursiveclojure.com/userguide/paredit.html). It is one of the most useful functionalities of Clojure IDEs and a direct consequence of the Clojure syntax.

I recommend you to check other functionalities from the manual. I really recommend checking the Cursive Clojure manual, it includes animations of how each functionality works.

You will use the last two key bindings quite a lot, so it is important to set them up correctly. There is more information about keybindings at https://cursiveclojure.com/userguide/keybindings.html.