Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

My First Clojure Workflow

DZone's Guide to

My First Clojure Workflow

· Java Zone
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

So, I was working with Clojure and… well… it seemed to be the worst combination of slow start-up and slow compilation… and it's supposed to be a dynamic language. So, I pinged the very nice people in the Clojure community and they pointed me in the right direction.

Basically, everything you do in Clojure, you do in the REPL. The REPL is a live coding environment.

Test First

I had been writing code and tests and then checking on my tests with: lein test But that was taking way too long (20 seconds per cycle on my MacBook Pro).

So, how does one test first in Clojure?

First, one starts the REPL:

lein repl

Then one changes the namespace to a test package:

(ns plugh.file-test )

And get the clojure.test package's functions:

(use 'clojure.test)

And run tests:

plugh.file-test=> (run-tests)




Testing plugh.file-test




Ran 2 tests containing 2 assertions.
0 failures, 0 errors.
{:type :summary, :pass 2, :test 2, :error 0, :fail 0}

Edit the tests and the test target, reload the tests and re-run them:

plugh.file-test=> (use 'plugh.file-test :reload-all)
nil
plugh.file-test=> (run-tests)




Testing plugh.file-test




FAIL in (foo-bar-test) (file_test.clj:22)
expected: (foo-bar)
actual: (not (foo-bar))




Ran 3 tests containing 3 assertions.
1 failures, 0 errors.
{:type :summary, :pass 2, :test 3, :error 0, :fail 1}
plugh.file-test=> 

Fix the function and re-run the tests:

plugh.file-test=> (use 'plugh.file-test :reload-all)
nil
plugh.file-test=> (run-tests)




Testing plugh.file-test




Ran 3 tests containing 3 assertions.
0 failures, 0 errors.
{:type :summary, :pass 3, :test 3, :error 0, :fail 0}
plugh.file-test=> 

The magic is when we :reload-all, then all the dependencies for the package being used are re-loaded as well. But in the REPL, the reload process takes no measurable time. This makes the cycle very, very fast. Change code, switch to the REPL, up-arrow twice, hit return, up-arrow twice, hit return and voila… your new test results.

Re-running the app

Next I'm going to tackle re-loading and re-running the app. This should bring the Clojure experience to something faster than the Scala/SBT experience.

Thanks!

Thanks to the folks on the Clojure mailing list who pointed me in the right direction.

And I will always keep the REPL at the front of my brain.

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.

Topics:

Published at DZone with permission of David Pollak. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}