DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > My First Clojure Workflow

My First Clojure Workflow

David Pollak user avatar by
David Pollak
·
Jun. 07, 13 · Java Zone · Interview
Like (0)
Save
Tweet
6.14K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Clojure workflow

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Ultimate Software Engineering Job Search Guide
  • Bad or Good? Behavior Driven Development within Scrum.
  • On Some Aspects of Big Data Processing in Apache Spark, Part 1: Serialization
  • MuleSoft Logs Integration With Datadog

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo