I’ve recently used a couple tools that I want to write about because I think they are pretty useful.
Eastwood is a linter, which will check your syntax to see if it is valid. BTW I have actually made this mistake for real! The github page lists all the things it checks for and a lot of how to configure eastwood.
To get started, Install into your lein profiles.clj:
My function, which by the way, is awesome:
1 2 3
lein eastwood in the project shows me:
1 2 3 4 5 6 7 8 9 10 11
Doh. The docstring is in the wrong place, correcting that and eastwood is happy. That is an easy mistake to make!
1 2 3 4 5 6 7
I’ve used eastwood a lot when I was developing amazon lambda functions, when I couldn’t see the result till I’ve uploaded to amazon. At first was frustrated only after all that to find an error which required me to do another compile to jar and upload. Now I use it before commit or when i’ve completed a unit of work or when I just can’t figure why something is not working..always a chance I did something stupid with syntax.
This library is for benchmarking clojure and I was using it to compare different implementations when I was working on adding some string functions to Clojure. Initially I added it to my lein profiles (similar to how i did with eastwood) which works fine for testing in the repl. Ghadi saw me talking about using it in Clojurians Slack and gave me a bash script to start any version of clojure and criterium with a repl:
1 2 3 4 5 6
Then save it as
repl-version.sh and run with
CLOJURE_VERSION=1.7.0 repl-version.sh to open a repl, then you can test away. I see this being useful when you are working on clojure itself or want to compare things in different versions of clojure. I used it when I was working on a patch for Clojure.
One of the things I used it for was figuring wanted to compare char? and instance? which should I use.. this is a true story! I was trying to figure this out one day..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
I wondered, how does
char? work? So I looked at the source:
1 2 3 4 5 6 7 8
Ahh, I see, it just checked the
instance? .. so I look what that function does:
1 2 3 4 5 6 7 8
So of course, instance will be faster than char …. If you know your class of object, it looks like instance? will always be a little faster. But there ya have benchmarking in Clojure with Criterium. :)
When reviewing this post, Ghadi said:
One small note, instance? is intrinsified by the compiler. It turns into a bytecode instruction. Which you can see in this clojure source. It’s faster than a function call.