Reader small image

You're reading from  Microservices with Clojure

Product typeBook
Published inJan 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788622240
Edition1st Edition
Languages
Right arrow
Author (1)
Anuj Kumar
Anuj Kumar
author image
Anuj Kumar

Anuj Kumar is the co-founder and chief architect of FORMCEPT, a data analytics startup based in Bangalore, India. He has more than 10 years of experience in designing large-scale distributed systems for storage, retrieval, and analytics. He has been in industry hacking, mainly in the area of data integration, data quality, and data analytics using NLP and machine learning techniques. He has published research papers at ACM conferences, got a few patents granted, and has spoken at TEDx. Prior to FORMCEPT, he has worked with the Oracle Server Technologies division in Bangalore, India.
Read more about Anuj Kumar

Right arrow

Chapter 4. Development Environment

"The mechanic that would perfect his work must first sharpen his tools."

- Confucius

The development environment consists of tools and libraries that are useful to implement, debug, and make changes to software systems. The efficiency of a development team is highly dependent on the development environment and technology stack at hand. In this chapter, you will learn how to set up a development environment for microservices using the Clojure ecosystem. This chapter will help you to:

  • Learn the history of Clojure and functional programming
  • Learn the importance of REPL
  • Learn how to build your application using Clojure build tools
  • Learn about well known integrated development environments (IDEs)

Clojure and REPL


Clojure (https://clojure.org/) is a dialect of the Lisp (https://en.wikipedia.org/wiki/Lisp_(programming_language) programming language and primarily runs on a Java virtual machine (JVM). The other target implementations include ClojureCLR (https://github.com/clojure/clojure-clr), which runs on Common Language Runtime (CLR), and ClojureScript, which compiles to JavaScript. Although Clojure uses a JVM as its underlying runtime engine, it emphasizes a functional programming language with immutability at its core. All data structures of Clojure are immutable. Since Clojure is a dialect of Lisp, it also treats code as data and is known to be homoiconic. Its syntax is built on S-expressions (https://en.wikipedia.org/wiki/S-expression) that are first parsed as a data structure and then translated into constructs of the Java programming language before being compiled into Java bytecode. Clojure also supports metaprogramming with macro (https://en.wikipedia.org/wiki/Macro_(computer_science...

Clojure build tools


Build tools are of prime importance for any programming language. They not only help to generate a deployable artifact for the application, but also manage the dependencies of the application throughout its development life cycle. Leiningen and Boot (http://boot-clj.com/) are two widely used build tools for Clojure. Since Clojure is a hosted language for JVM, Clojure build tools primarily generate JARs as deployable artifacts for all Clojure projects.

Leiningen

Leiningen is a build and project management tool that is written in Clojure and is widely used across Clojure projects. It describes a Clojure project using generic Clojure data structures. It integrates well with the Maven repository from the Java world and the Clojars (https://clojars.org/) repository of Clojure libraries, for dependency management and releases. Leiningen has built-in support for plugins to extend its functionality. It also provides an option to design application templates that can help create...

Clojure project


A Clojure project is a directory that contains source files, test files, resources, documentation, and project metadata. Source files are primarily from Clojure, but a project may contain Java source files as well. Leiningen has a default project template that can be used to quickly create a Clojure project structure using the lein new <project-name> command:

# Create a new project 'playground'
% lein new playground
Generating a project called playground based on the 'default' template.
The default template is intended for library projects, not applications.
To see other templates (app, plugin, etc), try `lein help new`.

# Show the 'playground' project directory structure
% tree playground
playground
├── CHANGELOG.md
├── doc
│   └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│   └── playground
│       └── core.clj
└── test
    └── playground
        └── core_test.clj

6 directories, 7 files

Each Clojure project contains a project metadata...

Clojure IDE


An integrated development environment (IDE) is a software application that provides utilities for programmers to develop, build, and debug software applications. It consists of a code editor, build automation tool, and a debugger. Clojure has a growing number of IDEs available, out of which Emacs (https://en.wikipedia.org/wiki/Emacs) and Vim (https://en.wikipedia.org/wiki/Vim_(text_editor)) stand out. Although this book does not cover IDEs, wherever one is referred to, uses Emacs as the IDE. Both Emacs and Vim are text editors that need additional plugins to support Clojure. Emacs needs CIDER (https://github.com/clojure-emacs/cider), whereas Vim gets REPL support using Fireplace (https://github.com/tpope/vim-fireplace).

Some  other Clojure IDEs that are widely used are:

Summary


In this chapter, we focused on the development environment for the Helping Hands application. Since Clojure is our language of choice for implementation, we first looked at the history of Clojure and Lisp and understood why it is well suited for our use case. We also looked at the REPL environment and two build tools for Clojure—Leiningen and Boot. Further, we defined a reference Leiningen project configuration for our application and learned how to run an application and test it. We also learned how to generate documentation and reports, and how to create a deployable artifact. At the end, we briefly looked at the Clojure IDEs that can make our application development work easy.

In the next chapter, we will learn about REST specification. We will learn how to define REST APIs for microservices in the Helping Hands application that can help with direct messaging among the services.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Microservices with Clojure
Published in: Jan 2018Publisher: PacktISBN-13: 9781788622240
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Anuj Kumar

Anuj Kumar is the co-founder and chief architect of FORMCEPT, a data analytics startup based in Bangalore, India. He has more than 10 years of experience in designing large-scale distributed systems for storage, retrieval, and analytics. He has been in industry hacking, mainly in the area of data integration, data quality, and data analytics using NLP and machine learning techniques. He has published research papers at ACM conferences, got a few patents granted, and has spoken at TEDx. Prior to FORMCEPT, he has worked with the Oracle Server Technologies division in Bangalore, India.
Read more about Anuj Kumar