Design by contract in Clojure

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

I posted a comment here:

I have gotten in the habit of doing 2 things:
1.) I used :pre and :post conditions as you are doing here
2.) I also use dire so when the :pre or :post conditions fail and an Assert exception is thrown, I can capture the arguments and the return value and write a meaningful error message:
https://github.com/MichaelDrogalis/dire
I do a lot of this:
:post [(:discount %)]
I also test for value ranges:
:post
[
(> (:totals %) 100)
(< (:totals %) 1000) ] I am thinking I might use prismatic/schema in the future.

Post external references

  1. 1
    http://theholyjava.wordpress.com/2014/04/30/clojure-how-to-prevent-expected-map-got-vector-and-similar-errors/#comment-6648
Source